How do i integrate Hoptoad with DelayedJob and DaemonSpawn?
hoptoad, ruby, ruby-on-rails
Solution
Try monkeypatching Delayed::Worker#handle_failed_job :
# lib/delayed_job_airbrake.rb
module Delayed
class Worker
protected
def handle_failed_job_with_airbrake(job, error)
say "Delayed job failed -- logging to Airbrake"
HoptoadNotifier.notify(error)
handle_failed_job_without_airbrake(job, error)
end
alias_method_chain :handle_failed_job, :airbrake
end
end
This worked for me.
(in a Rails 3.0.10 app using delayed_job 2.1.4 and hoptoad_notifier 2.4.11)
Problem
I have been happily using the DelayedJob idiom: ``` foo.send_later(:bar) ``` This calls the method bar on the object foo in the DelayedJob process. And I've been using DaemonSpawn to kick off the DelayedJob process on my server. But... if foo throws an exception Hoptoad doesn't catch it. Is this a bug in any of these packages... or do I need to change some configuration... or do I need to insert some exception handling in DS or DJ that will call the Hoptoad notifier? In response to the first comment below. ``` class DelayedJobWorker < DaemonSpawn::Base def start(args) ENV['RAILS_ENV'] ||= args.first || 'development' Dir.chdir RAILS_ROOT require File.join('config', 'environment') Delayed::Worker.new.start end ```