如何将 Hoptoad 与 DelayedJob 和 DaemonSpawn 集成? [英] How do i integrate Hoptoad with DelayedJob and DaemonSpawn?
问题描述
我一直很高兴使用 DelayedJob 习语:
I have been happily using the DelayedJob idiom:
foo.send_later(:bar)
这会调用 DelayedJob 进程中对象 foo 上的方法 bar.
This calls the method bar on the object foo in the DelayedJob process.
而且我一直在使用 DaemonSpawn 在我的服务器上启动 DelayedJob 进程.
And I've been using DaemonSpawn to kick off the DelayedJob process on my server.
但是...如果 foo 抛出异常 Hoptoad 不会捕获它.
But... if foo throws an exception Hoptoad doesn't catch it.
这是这些软件包中的任何一个中的错误...还是我需要更改一些配置...或者我是否需要在 DS 或 DJ 中插入一些异常处理来调用 Hoptoad 通知程序?
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
推荐答案
Try monkeypatching Delayed::Worker#handle_failed_job :
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
这对我有用.
(在使用延迟作业 2.1.4 和 hoptoad_notifier 2.4.11 的 Rails 3.0.10 应用程序中)
(in a Rails 3.0.10 app using delayed_job 2.1.4 and hoptoad_notifier 2.4.11)
这篇关于如何将 Hoptoad 与 DelayedJob 和 DaemonSpawn 集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!