Pedro Rolo
Pedro Rolo

Reputation: 29930

How to run and stop a delayed_jobs worker in a Thread or Subprocess for testing purposes

I would like to be able to perform some tests that require a worker to be running.

In order to accomplish 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?

Upvotes: 1

Views: 630

Answers (1)

jdl
jdl

Reputation: 17790

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.

Upvotes: 2

Related Questions