在delayed_job中,当Delayed::Worker.delay_jobs为假时是否会调用钩子?
我正在使用 collectiveidea/delayed_job。在我的 RSpec 测试中,[:before, :after, :success] 挂钩没有像我预期的那样被调用。
当 Delayed::Worker.delay_jobs = true (默认)时,我看到 enqueue()
钩子被调用,仅此而已。这是我期望的行为,因为没有单独的任务处理作业。
但是,当 Delayed::Worker.delay_jobs = false 时(按照文档测试的建议),我看到我的 process() 方法被调用,但没有任何钩子。
如果这不是预期的行为,对我做错了什么有什么建议吗? (我可以轻松地包含代码。)如果这是预期的行为,那么测试挂钩的策略是什么?
[旁注:delayed_job 的规范目录,特别是 performable_method_spec 测试,建议您可以设置 Delayed::Worker.delay_jobs = false
并仍然获得对您的钩子的回调。但这些测试使用 obj.delay.method 构造而不是 Delayed::Job.enqueue(object_with_a_perform_method) 来将作业排入队列。这会有所不同吗?]
[更新:我尝试过 obj.delay.method 形式以及 Delayed::Job.enqueue(obj_with_a_perform_method) 形式 - - 在这两种情况下我都没有看到钩子被调用。]
I'm using collectiveidea/delayed_job. In my RSpec tests, the [:before, :after, :success] hooks aren't getting called as I would expect.
When Delayed::Worker.delay_jobs = true
(the default), I see the enqueue()
hook getting called and nothing more. This is the behavior I expect, since there's no separate task processing the jobs.
But when Delayed::Worker.delay_jobs = false
, as recommended for testing by the documents, I see my process() method getting called, but none of of the hooks.
If this is not the expected behavior, any suggestions on what I'm doing wrong? (I can easily include code.) If this is the expected behavior, then what's a strategy for testing the hooks?
[Side note: The spec directory for delayed_job, notably the performable_method_spec tests, suggest that you can set Delayed::Worker.delay_jobs = false
and still get callbacks to your hooks. But those tests are using the obj.delay.method
construct rather than Delayed::Job.enqueue(object_with_a_perform_method)
to enqueue the job. Would this make a difference?]
[Update: I've tried the obj.delay.method
form as well as the Delayed::Job.enqueue(obj_with_a_perform_method)
form -- I don't see the hooks getting called in either case.]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在collectiveidea/delayed_job github页面上,我发现了同样的错误描述、修复和拉。据推测,delayed_job 的更新版本将解决该问题。
更新:除了拉取最新版本之外,我找到了解决方法。您可以显式调用 Delayed::Job 工作器方法。它将处理队列中的项目——当然与测试在同一个线程中——但是回调挂钩确实会被调用:
On the collectiveidea/delayed_job github page, I found this very same bug described, fixed, and pulled. Presumably an updated version of delayed_job will fix the problem.
Update: I've found a workaround other than pulling the latest version. You can explicitly call the Delayed::Job worker method. It will process items in the queue -- in the same thread as the tests of course -- but the callback hooks do get called: