From 175c73540e343457e9ee1748981b7e3458c7f458 Mon Sep 17 00:00:00 2001 From: Sergey Kojin Date: Sat, 13 Feb 2016 18:57:20 +0300 Subject: [PATCH 1/2] don't send error when job have reschedule attempts, only when job fail last time --- lib/delayed-plugins-airbrake.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/delayed-plugins-airbrake.rb b/lib/delayed-plugins-airbrake.rb index 28b71c9..d03a0c8 100644 --- a/lib/delayed-plugins-airbrake.rb +++ b/lib/delayed-plugins-airbrake.rb @@ -8,15 +8,17 @@ 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 - } - ) + 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 From 6247542c21fe7d5319136321d4826bfa310286a1 Mon Sep 17 00:00:00 2001 From: Sergey Kojin Date: Mon, 11 Sep 2017 12:49:10 +0300 Subject: [PATCH 2/2] don't airbrake if custom error handler defined --- lib/delayed-plugins-airbrake.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/delayed-plugins-airbrake.rb b/lib/delayed-plugins-airbrake.rb index d03a0c8..f3233a8 100644 --- a/lib/delayed-plugins-airbrake.rb +++ b/lib/delayed-plugins-airbrake.rb @@ -8,6 +8,8 @@ module Delayed::Plugins::Airbrake class Plugin < ::Delayed::Plugin module Notify def error(job, exception) + 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,