diff --git a/Gemfile.lock b/Gemfile.lock index 94238d842..5792cddad 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -131,8 +131,7 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - chef-utils (17.9.18) - concurrent-ruby + chef-utils (16.6.14) childprocess (3.0.0) coderay (1.1.3) concurrent-ruby (1.1.9) @@ -158,16 +157,17 @@ GEM erubi (1.10.0) et-orbi (1.2.6) tzinfo - faraday (1.8.0) + faraday (1.9.3) faraday-em_http (~> 1.0) faraday-em_synchrony (~> 1.0) faraday-excon (~> 1.1) - faraday-httpclient (~> 1.0.1) + faraday-httpclient (~> 1.0) + faraday-multipart (~> 1.0) faraday-net_http (~> 1.0) - faraday-net_http_persistent (~> 1.1) + faraday-net_http_persistent (~> 1.0) faraday-patron (~> 1.0) faraday-rack (~> 1.0) - multipart-post (>= 1.2, < 3) + faraday-retry (~> 1.0) ruby2_keywords (>= 0.0.4) faraday-em_http (1.0.0) faraday-em_synchrony (1.0.0) @@ -175,10 +175,13 @@ GEM faraday-http-cache (2.2.0) faraday (>= 0.8) faraday-httpclient (1.0.1) + faraday-multipart (1.0.2) + multipart-post (>= 1.2, < 3) faraday-net_http (1.0.1) faraday-net_http_persistent (1.2.0) faraday-patron (1.0.0) faraday-rack (1.0.0) + faraday-retry (1.0.3) ffi (1.15.4) ffi (1.15.4-java) fiber-local (1.0.0) @@ -243,7 +246,7 @@ GEM sawyer (~> 0.8.0, >= 0.5.3) optimist (3.0.1) parallel (1.21.0) - parser (3.0.3.2) + parser (3.1.0.0) ast (~> 2.4.1) pg (1.2.3) protocol-hpack (1.4.2) @@ -338,7 +341,7 @@ GEM unicode-display_width (>= 1.4.0, < 3.0) rubocop-ast (1.15.1) parser (>= 3.0.1.1) - rubocop-performance (1.13.0) + rubocop-performance (1.13.1) rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) rubocop-rails (2.13.0) @@ -367,7 +370,7 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - thor (1.1.0) + thor (1.2.1) timers (4.3.3) tomlrb (2.0.1) tzinfo (2.0.4) diff --git a/lib/good_job/notifier.rb b/lib/good_job/notifier.rb index 54d4274ca..7e8a262f7 100644 --- a/lib/good_job/notifier.rb +++ b/lib/good_job/notifier.rb @@ -16,9 +16,6 @@ class Notifier include Notifier::ProcessRegistration - # Raised if the Database adapter does not implement LISTEN. - AdapterCannotListenError = Class.new(StandardError) - # Default Postgres channel for LISTEN/NOTIFY CHANNEL = 'good_job' # Defaults for instance of Concurrent::ThreadPoolExecutor @@ -129,8 +126,6 @@ def restart(timeout: -1) # @!visibility private # @return [void] def listen_observer(_time, _result, thread_error) - return if thread_error.is_a? AdapterCannotListenError - if thread_error GoodJob._on_thread_error(thread_error) ActiveSupport::Notifications.instrument("notifier_notify_error.good_job", { error: thread_error }) @@ -214,6 +209,15 @@ def wait_for_notify raw_connection.wait_for_notify(WAIT_INTERVAL) do |channel, _pid, payload| yield(channel, payload) end + elsif raw_connection.respond_to?(:jdbc_connection) + raw_connection.execute_query("SELECT 1") + notifications = raw_connection.jdbc_connection.getNotifications + Array(notifications).each do |notification| + channel = notification.getName + payload = notification.getParameter + yield(channel, payload) + end + sleep WAIT_INTERVAL else sleep WAIT_INTERVAL end diff --git a/spec/lib/good_job/notifier_spec.rb b/spec/lib/good_job/notifier_spec.rb index 5ad5789ab..ce4b1cf12 100644 --- a/spec/lib/good_job/notifier_spec.rb +++ b/spec/lib/good_job/notifier_spec.rb @@ -19,7 +19,7 @@ end end - describe '#listen', skip_if_java: true do + describe '#listen' do it 'loops until it receives a command' do stub_const 'RECEIVED_MESSAGE', Concurrent::AtomicBoolean.new(false) @@ -42,10 +42,11 @@ notifier = described_class.new sleep_until(max: 5, increments_of: 0.5) { notifier.listening? } + described_class.notify(true) - notifier.shutdown + wait_until(max: 5, increments_of: 0.5) { expect(on_thread_error).to have_received(:call).at_least(:once).with instance_of(ExpectedError) } - expect(on_thread_error).to have_received(:call).at_least(:once).with instance_of(ExpectedError) + notifier.shutdown end end diff --git a/spec/test_app/config/initializers/good_job.rb b/spec/test_app/config/initializers/good_job.rb index f6dcffb31..60c659bf2 100644 --- a/spec/test_app/config/initializers/good_job.rb +++ b/spec/test_app/config/initializers/good_job.rb @@ -14,7 +14,7 @@ GoodJob.retry_on_unhandled_error = false GoodJob.preserve_job_records = true - GoodJob.on_thread_error = -> (error) { Rails.logger.warn(error) } + GoodJob.on_thread_error = -> (error) { Rails.logger.warn("#{error}\n#{error.backtrace}") } Rails.application.configure do config.good_job.enable_cron = ActiveModel::Type::Boolean.new.cast(ENV.fetch('GOOD_JOB_ENABLE_CRON', true))