Class: ExceptionHunter::Middleware::DelayedJobHunter
- Inherits:
-
Delayed::Plugin
- Object
- Delayed::Plugin
- ExceptionHunter::Middleware::DelayedJobHunter
- Defined in:
- lib/exception_hunter/middleware/delayed_job_hunter.rb
Overview
DelayedJob plugin to track exceptions on apps using DelayedJob.
Constant Summary collapse
- TRACK_AT_RETRY =
[0, 3, 6, 10].freeze
- JOB_TRACKED_DATA =
%w[ attempts ].freeze
- ARGS_TRACKED_DATA =
%w[ queue_name job_class job_id arguments enqueued_at ].freeze
Class Method Summary collapse
- .environment_data(job) ⇒ Object
- .should_track?(attempts) ⇒ Boolean
- .track_exception(exception, job) ⇒ Object
Class Method Details
.environment_data(job) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/exception_hunter/middleware/delayed_job_hunter.rb', line 43 def self.environment_data(job) job_data = JOB_TRACKED_DATA.reduce({}) do |dict, data_param| dict.merge(data_param => job.try(data_param)) end job_class = if job.payload_object.class.name == 'ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper' # support for Rails 4.2 ActiveJob job.payload_object.job_data['job_class'] elsif job.payload_object.object.is_a?(Class) job.payload_object.object.name else job.payload_object.object.class.name end args_data = (job.payload_object.try(:job_data) || {}).select { |key, _value| ARGS_TRACKED_DATA.include?(key) } args_data['job_class'] = job_class || job.payload_object.class.name if args_data['job_class'].nil? job_data.merge(args_data) end |
.should_track?(attempts) ⇒ Boolean
64 65 66 |
# File 'lib/exception_hunter/middleware/delayed_job_hunter.rb', line 64 def self.should_track?(attempts) TRACK_AT_RETRY.include?(attempts) end |
.track_exception(exception, job) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/exception_hunter/middleware/delayed_job_hunter.rb', line 30 def self.track_exception(exception, job) return unless should_track?(job.attempts) ErrorCreator.call( async_logging: false, tag: ErrorCreator::WORKER_TAG, class_name: exception.class.to_s, message: exception., environment_data: environment_data(job), backtrace: exception.backtrace ) end |