in delayed_job, are hooks called when Delayed::Worker.delay_jobs is false?
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.]
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:
[successes, failures] = Delayed::Worker.new.work_off
精彩评论