I was just searching for a solution to this problem too, and I found this gist.
I don't know where it comes from (found it on Google), but well, it seems to do the job pretty well, is quite simple, and seems to follow a DelayedJob's plugin system I was not even aware of...
Here is a lightly improved one using parts of previous monkey-patch code:
# https://gist.github.com/2223758
# modified
module Delayed
module Plugins
class Airbrake < Plugin
module Notify
def error(job, error)
::Airbrake.notify_or_ignore(
:error_class => error.class.name,
:error_message => "#{error.class.name}: #{error.message}",
:parameters => {
:failed_job => job.inspect,
}
)
super if defined?(super)
end
end
callbacks do |lifecycle|
lifecycle.before(:invoke_job) do |job|
payload = job.payload_object
payload = payload.object if payload.is_a? Delayed::PerformableMethod
payload.extend Notify
end
end
end
end
end
Delayed::Worker.plugins << Delayed::Plugins::Airbrake
It will add the error's message and payload so that it's available in Airbrake.