如何将 Hoptoad 与 DelayedJob 和 DaemonSpawn 集成?
我一直很高兴地使用 DelayedJob 习惯用法:
foo.send_later(:bar)
这在 DelayedJob 进程中调用对象 foo 上的方法 bar。
我一直在使用 DaemonSpawn 在我的服务器上启动 DelayedJob 进程。
但是...如果 foo 抛出异常 Hoptoad 不会捕获它。
这是这些软件包中的一个错误吗...或者我是否需要更改某些配置...或者我是否需要在 DS 或 DJ 中插入一些异常处理来调用 Hoptoad 通知程序?
回应下面的第一条评论。
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试monkeypatching Delayed::Worker#handle_failed_job:
这对我有用。
(在使用delayed_job 2.1.4和hoptoad_notifier 2.4.11的Rails 3.0.10应用程序中)
Try monkeypatching Delayed::Worker#handle_failed_job :
This worked for me.
(in a Rails 3.0.10 app using delayed_job 2.1.4 and hoptoad_notifier 2.4.11)
查看 Delayed::Job 的来源...有一个片段,例如:
我还没有尝试过,但我认为你可以这样做:
Check out the source for Delayed::Job... there's a snippet like:
I haven't tried it, but I think you could do something like:
Hoptoad 使用 Rails
rescue_action_in_public
挂钩方法来拦截异常并记录它们。 仅当 Rails 控制器分派请求时才会执行此方法。因此,Hoptoad 完全不知道生成的任何异常,例如由 rake 任务或 Rails 脚本/运行程序生成的异常。
如果您想让 Hoptoad 跟踪您的异常,您应该手动集成它。
这应该是非常简单的。 以下代码片段演示了如何调用 Hoptoad
只需在您的环境中包含 Hoptoad 库并调用
notify_hoptoad(exception)
就可以了。 确保您的环境提供与 Rails 控制器相同的 API,否则 Hoptoad 可能会抱怨。Hoptoad uses the Rails
rescue_action_in_public
hook method to intercept exceptions and log them. This method is only executed when the request is dispatched by a Rails controller.For this reason, Hoptoad is completely unaware of any exception generated, for example, by rake tasks or the rails script/runner.
If you want to have Hoptoad tracking your exception, you should manually integrate it.
It should be quite straightforward. The following code fragment demonstrates how Hoptoad is invoked
Just include Hoptoad library in your environment and call
notify_hoptoad(exception)
should work. Make sure your environment provides the same API of a Rails controller or Hoptoad might complain.只是把它扔在那里 - 你的守护进程应该需要你正在处理的 Rails 环境。 它看起来应该类似于:
通过这种方式,您可以指定调用守护程序的环境。
因为它运行延迟作业,所以守护进程已经这样做了(它需要 activerecord),但也许您只需要最少的 activerecord 即可在没有rails的情况下使delayed_job满意。
Just throwing it out there - your daemon should require the rails environment that you're working on. It should look something along the lines of:
This way you can specify environment in which daemon is called.
Since it runs delayed job chances are daemon already does that (it needs activerecord), but maybe you're only requiring minimal activerecord to make delayed_job happy without rails.