I would like to be able to perform some tests that require a worker to be running.
In order to accompli开发者_StackOverflow中文版sh this created this test helper method:
def with_delayed_jobs
t=Thread.new {Delayed::Worker.new.start}
sleep(5)
yield
t.exit
end
So I can write in my tests
with_delayed_jobs {
___test_content___
}
Unfortunately, the worker doesn't seem to run this way. Maybe I can do it with processes. Does anybody have an idea on how to accomplish this?
You can run the jobs that are currently in your jobs table with this:
Delayed::Worker.new(
:max_priority => nil,
:min_priority => nil,
:quiet => true
).work_off
Docs are here, although they are sparse.
精彩评论