lib/good_job/notifier.rb in good_job-1.3.6 vs lib/good_job/notifier.rb in good_job-1.4.0

- old
+ new

@@ -7,10 +7,12 @@ # Notifiers can emit NOTIFY messages through Postgres. # A notifier will LISTEN for messages by creating a background thread that runs in an instance of +Concurrent::ThreadPoolExecutor+. # When a message is received, the notifier passes the message to each of its recipients. # class Notifier + AdapterCannotListenError = Class.new(StandardError) + # Default Postgres channel for LISTEN/NOTIFY CHANNEL = 'good_job'.freeze # Defaults for instance of Concurrent::ThreadPoolExecutor POOL_OPTIONS = { name: name, @@ -92,10 +94,12 @@ # Invoked on completion of ThreadPoolExecutor task # @!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.call(thread_error) if GoodJob.on_thread_error.respond_to?(:call) ActiveSupport::Notifications.instrument("notifier_notify_error.good_job", { error: thread_error }) end @@ -147,9 +151,11 @@ def with_listen_connection ar_conn = ActiveRecord::Base.connection_pool.checkout.tap do |conn| ActiveRecord::Base.connection_pool.remove(conn) end pg_conn = ar_conn.raw_connection + raise AdapterCannotListenError unless pg_conn.respond_to? :wait_for_notify + pg_conn.async_exec("SET application_name = #{pg_conn.escape_identifier(self.class.name)}").clear yield pg_conn ensure ar_conn&.disconnect! end