Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop Ruby 2.4 support #142

Merged
merged 1 commit into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ inherit_mode:
- Include

AllCops:
TargetRubyVersion: 2.4.0
TargetRubyVersion: 2.5
DisplayCopNames: true
DisplayStyleGuide: true
Include:
Expand Down
2 changes: 1 addition & 1 deletion good_job.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Gem::Specification.new do |spec|
"--quiet"
]

spec.required_ruby_version = ">= 2.4.0"
spec.required_ruby_version = ">= 2.5.0"

spec.add_dependency "activejob", ">= 5.1.0"
spec.add_dependency "activerecord", ">= 5.1.0"
Expand Down
52 changes: 25 additions & 27 deletions lib/good_job/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,38 +98,36 @@ def create_pool

def listen
future = Concurrent::Future.new(args: [@recipients, @pool, @listening], executor: @pool) do |recipients, pool, listening|
begin
with_listen_connection do |conn|
ActiveSupport::Notifications.instrument("notifier_listen.good_job") do
conn.async_exec "LISTEN #{CHANNEL}"
end
with_listen_connection do |conn|
ActiveSupport::Notifications.instrument("notifier_listen.good_job") do
conn.async_exec "LISTEN #{CHANNEL}"
end

ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
while pool.running?
listening.make_true
conn.wait_for_notify(WAIT_INTERVAL) do |channel, _pid, payload|
listening.make_false
next unless channel == CHANNEL

ActiveSupport::Notifications.instrument("notifier_notified.good_job", { payload: payload })
parsed_payload = JSON.parse(payload, symbolize_names: true)
recipients.each do |recipient|
target, method_name = recipient.is_a?(Array) ? recipient : [recipient, :call]
target.send(method_name, parsed_payload)
end
end
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
while pool.running?
listening.make_true
conn.wait_for_notify(WAIT_INTERVAL) do |channel, _pid, payload|
listening.make_false
next unless channel == CHANNEL

ActiveSupport::Notifications.instrument("notifier_notified.good_job", { payload: payload })
parsed_payload = JSON.parse(payload, symbolize_names: true)
recipients.each do |recipient|
target, method_name = recipient.is_a?(Array) ? recipient : [recipient, :call]
target.send(method_name, parsed_payload)
end
end
listening.make_false
end
end
rescue StandardError => e
ActiveSupport::Notifications.instrument("notifier_notify_error.good_job", { error: e })
raise
ensure
@listening.make_false
ActiveSupport::Notifications.instrument("notifier_unlisten.good_job") do
conn.async_exec "UNLISTEN *"
end
end
rescue StandardError => e
ActiveSupport::Notifications.instrument("notifier_notify_error.good_job", { error: e })
raise
ensure
@listening.make_false
ActiveSupport::Notifications.instrument("notifier_unlisten.good_job") do
conn.async_exec "UNLISTEN *"
end
end

Expand Down
16 changes: 7 additions & 9 deletions spec/lib/good_job/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,13 @@ def perform(result_value = nil, raise_error: false)
# Similar to Sentry monitor's implementation
# https://github.com/getsentry/raven-ruby/blob/20b260a6d04e0ca01d5cddbd9728e6fc8ae9a90c/lib/raven/integrations/rails/active_job.rb#L21-L31
ExampleJob.around_perform do |_job, block|
begin
block.call
rescue StandardError => e
next if rescue_with_handler(e)

raise e
ensure
nil
end
block.call
rescue StandardError => e
next if rescue_with_handler(e)

raise e
ensure
nil
end
end

Expand Down
8 changes: 3 additions & 5 deletions spec/support/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ module SystemTestHelpers
:dismiss_modal,
].each do |driver_method|
define_method(driver_method) do |text = nil, **options, &blk|
begin
super(text, **options, &blk)
rescue Capybara::NotSupportedByDriverError
blk.call
end
super(text, **options, &blk)
rescue Capybara::NotSupportedByDriverError
blk.call
end
end
end
Expand Down