lib/airbrake/delayed_job.rb in airbrake-9.5.5 vs lib/airbrake/delayed_job.rb in airbrake-10.0.0

- old
+ new

@@ -1,34 +1,50 @@ module Delayed module Plugins # Provides integration with Delayed Job. - # rubocop:disable Lint/RescueException + # rubocop:disable Metrics/BlockLength class Airbrake < ::Delayed::Plugin callbacks do |lifecycle| lifecycle.around(:invoke_job) do |job, *args, &block| begin - # Forward the call to the next callback in the callback chain - block.call(job, *args) - rescue Exception => exception + timing = ::Airbrake::Benchmark.measure do + # Forward the call to the next callback in the callback chain + block.call(job, *args) + end + rescue Exception => exception # rubocop:disable Lint/RescueException params = job.as_json # If DelayedJob is used through ActiveJob, it contains extra info. if job.payload_object.respond_to?(:job_data) params[:active_job] = job.payload_object.job_data job_class = job.payload_object.job_data['job_class'] end + action = job_class || job.payload_object.class.name + ::Airbrake.notify(exception, params) do |notice| notice[:context][:component] = 'delayed_job' - notice[:context][:action] = job_class || job.payload_object.class.name + notice[:context][:action] = action end + ::Airbrake.notify_queue_sync( + queue: action, + error_count: 1, + timing: 0.01, + ) + raise exception + else + ::Airbrake.notify_queue_sync( + queue: job_class || job.payload_object.class.name, + error_count: 0, + timing: timing, + ) end end end end - # rubocop:enable Lint/RescueException + # rubocop:enable Metrics/BlockLength end end if RUBY_ENGINE == 'jruby' && defined?(Delayed::Backend::ActiveRecord::Job) # Workaround against JRuby bug: