I’m using collectiveidea’s version of delayed_job: https://github.com/collectiveidea/delayed_job
Can anyone point me to the actual criteria used when a worker goes to pick the next job to work on? I’m assuming it’s something like “SELECT id FROM delayed_jobs WHERE run_at > NOW() ORDER BY priority ASC, run_at ASC LIMIT 1” (picks by priority first, run_at time second), but I haven’t been able to find exactly what’s considered. I’ve done some poking about in the code on GitHub, but haven’t found the actual query for the next job. Curious on a couple things, including whether ‘created_at’, ‘attempts’ or ‘failed_at’ factor into prioritization at all. (and I realize I’m unlikely to find actual SQL, just an easy way to represent what I assume the query does).
Secondarily, any good sources of actual documentation for this gem? For something that’s used so commonly in Rails, the documentation I’ve seen is pretty darn sparse.
A bit of digging through the source showed this in backend/active_record.rb:
Also, this bit in backend/base.rb is of interest:
reserveis called by a worker to choose the next job.