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..7f330fba6 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) 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))