diff --git a/lib/delayed-plugins-airbrake.rb b/lib/delayed-plugins-airbrake.rb index 28b71c9..f3233a8 100644 --- a/lib/delayed-plugins-airbrake.rb +++ b/lib/delayed-plugins-airbrake.rb @@ -8,15 +8,19 @@ module Delayed::Plugins::Airbrake class Plugin < ::Delayed::Plugin module Notify def error(job, exception) - ::Airbrake.notify(exception, - :error_class => exception.class.name, - :error_message => "#{exception.class.name}: #{exception.message}", - :backtrace => exception.backtrace, - :component => 'DelayedJob Worker', - :parameters => { - :failed_job => job.inspect - } - ) + return if defined?(super) # don't airbrake if custom handler defined + + if (job.attempts + 1) >= (job.max_attempts || Delayed::Worker.max_attempts) + ::Airbrake.notify(exception, + :error_class => exception.class.name, + :error_message => "#{exception.class.name}: #{exception.message}", + :backtrace => exception.backtrace, + :component => 'DelayedJob Worker', + :parameters => { + :failed_job => job.inspect + } + ) + end super if defined?(super) end end