Module: Axn::Async::Adapters::Sidekiq::DeathHandler
- Defined in:
- lib/axn/async/adapters/sidekiq/death_handler.rb
Overview
Sidekiq death handler that triggers on_exception when retries are exhausted. This is used when async_exception_reporting is set to :first_and_exhausted or :only_exhausted.
To enable, add to your Sidekiq server configuration:
Sidekiq.configure_server do |config|
config.death_handlers << Axn::Async::Adapters::Sidekiq::DeathHandler
end
Class Method Summary collapse
Class Method Details
.call(job, exception) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/axn/async/adapters/sidekiq/death_handler.rb', line 21 def call(job, exception) # Only handle Axn jobs klass = job["class"].to_s.safe_constantize return unless klass&.included_modules&.include?(Axn::Core) # Use per-class override if set, otherwise fall back to global config config_mode = klass.try(:_async_exception_reporting) || Axn.config.async_exception_reporting return if config_mode == :every_attempt # Already reported on each attempt retry_context = RetryHelpers.build_retry_context(job, from_death_handler: true) # For :first_and_exhausted, we need to report now (exhausted) # For :only_exhausted, we need to report now (only time) return unless retry_context.should_trigger_on_exception?(config_mode, from_exhaustion_handler: true) job_args = (job["args"]&.first || {}).symbolize_keys ExceptionReporting.trigger_on_exception( exception:, action_class: klass, retry_context:, job_args:, extra_context: { _job_metadata: { job_class: job["class"], jid: job["jid"], queue: job["queue"], created_at: job["created_at"], failed_at: job["failed_at"], error_class: job["error_class"], error_message: job["error_message"], }.compact, }, log_prefix: "Sidekiq death handler", ) end |