lib/good_job/notifier.rb in good_job-2.6.0 vs lib/good_job/notifier.rb in good_job-2.6.1
- old
+ new
@@ -23,14 +23,21 @@
auto_terminate: true,
idletime: 60,
max_queue: 1,
fallback_policy: :discard,
}.freeze
- # Seconds to wait if database cannot be connected to
- RECONNECT_INTERVAL = 5
# Seconds to block while LISTENing for a message
WAIT_INTERVAL = 1
+ # Seconds to wait if database cannot be connected to
+ RECONNECT_INTERVAL = 5
+ # Connection errors that will wait {RECONNECT_INTERVAL} before reconnecting
+ CONNECTION_ERRORS = %w[
+ ActiveRecord::ConnectionNotEstablished
+ ActiveRecord::StatementInvalid
+ PG::UnableToSend
+ PG::Error
+ ].freeze
# @!attribute [r] instances
# @!scope class
# List of all instantiated Notifiers in the current process.
# @return [Array<GoodJob::Notifier>, nil]
@@ -113,18 +120,21 @@
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 })
+
+ connection_error = CONNECTION_ERRORS.any? do |error_string|
+ error_class = error_string.safe_constantize
+ next unless error_class
+
+ thread_error.is_a? error_class
+ end
end
return if shutdown?
- if thread_error.is_a?(ActiveRecord::ConnectionNotEstablished) || thread_error.is_a?(ActiveRecord::StatementInvalid)
- listen(delay: RECONNECT_INTERVAL)
- else
- listen
- end
+ listen(delay: connection_error ? RECONNECT_INTERVAL : 0)
end
private
attr_reader :executor