que-rb/que

Que::Job with no run_at setting skips Que entirely

jnicho02 opened this issue · 3 comments

Is it my imagination, or does a Que::Job with solely a run() method and no overridden self.run_at not only run immediately, but actually skip the Que entirely? Is this the desired behaviour because it affects which worker does the work.

In my case, I run Rails on Heroku with Que on its own worker, thus keeping the main web worker threads lightly loaded. Sure, I can set a run_at of 1.second to make it happen almost immediately on the Que worker but it feels a bit messy.

Happy to be wrong if I've missed something somewhere.

(Que version 1.3.1)

In normal (asynchronous) mode, a job will run immediately, but in a worker process. You can confirm the behaviour by logging the PID when scheduling the job and when executing the job. Be sure that you're using synchronous mode (Que::Job.run_synchronously = true) only in your tests.

Edit: Alternatively, you can put a sleep in #run, and inspect the records in the que_jobs table to see that it's in there.

Ah, it is down to the synchronous mode. My jobs are quite memory-intensive, and with multiple Que workers were overwhelming the 512Mb memory allocation of the Heroku worker so I set them to running synchronously as a quick way to limit the strain....and it was doing exactly what I told it to do.

So, the answer is "set the worker_count to 1 if you want to run one-at-a-time, don't abuse the run_synchronously setting which is really only for tests".

Thanks for your assistance. Really liking Que.

Haha, good to hear