Todd R
Todd R

Reputation: 18516

Delayed::Job run_at not being honored in cucumber test

I'm running an existing cucumber suite that exercises code that enqueues delayed jobs, none of which include any "run_at" conditions. However, I've now introduced a job that gets enqueued with "run_at" in the future, and it does exactly what I want. However, when I exercise my new feature, I find the job is being executed immediately.

I found this somewhat promising line in a setup file:

# Run all delayed jobs inline
Delayed::Worker.delay_jobs = false

I hoped that changing the value to true would help, but that causes none of the jobs to be run.

So how do I get the run_at to be honored and still have other jobs run as soon as they're enqueued?

Upvotes: 0

Views: 139

Answers (2)

stevenspiel
stevenspiel

Reputation: 5999

DelayedJob 4.1.0 now supports Delayed::Worker.delay_jobs being a block.

You could do:

Delayed::Worker.delay_jobs = ->(job) {
  job.run_at && job.run_at > Time.now.utc
}

Upvotes: 0

Todd R
Todd R

Reputation: 18516

So, this now makes sense. The "Delayed::Worker.delay_jobs = false" causes jobs to be executed inline. Setting it to true puts the jobs in the database . . . where they sit forever because I don't have anything in place to work them off!

Upvotes: 1

Related Questions