class ExceptionHunter::Middleware::SidekiqHunter
Middleware
to report errors when a Sidekiq worker fails
Constants
- ARGS_TRACKED_DATA
- JOB_TRACKED_DATA
- TRACK_AT_RETRY
Public Instance Methods
call(_worker, context, _queue) { || ... }
click to toggle source
# File lib/exception_hunter/middleware/sidekiq_hunter.rb, line 18 def call(_worker, context, _queue) yield rescue Exception => exception # rubocop:disable Lint/RescueException track_exception(exception, context) raise exception end
Private Instance Methods
environment_data(context)
click to toggle source
# File lib/exception_hunter/middleware/sidekiq_hunter.rb, line 40 def environment_data(context) job_data = context.select { |key, _value| JOB_TRACKED_DATA.include?(key) } args_data = (context['args']&.first || {}).select { |key, _value| ARGS_TRACKED_DATA.include?(key) } job_data.merge(args_data) end
should_track?(context)
click to toggle source
# File lib/exception_hunter/middleware/sidekiq_hunter.rb, line 47 def should_track?(context) TRACK_AT_RETRY.include?(context['retry_count'].to_i) end
track_exception(exception, context)
click to toggle source
# File lib/exception_hunter/middleware/sidekiq_hunter.rb, line 27 def track_exception(exception, context) return unless should_track?(context) ErrorCreator.call( async_logging: false, tag: ErrorCreator::WORKER_TAG, class_name: exception.class.to_s, message: exception.message, environment_data: environment_data(context), backtrace: exception.backtrace ) end