ryandotsmith/queue_classic — pull request #197 by erykwalder (2014-03-04 20:18:51+00:00)
Title: Account for locked_at in job_count query

This prevents relative_count being greater than the number of runnable jobs in the job selection query.

If a queue has locked failed jobs in the table, then lock_head will sometimes return no result based upon its randomly generated offset. The random offset (relative_top) used in the query is greater than the number of runnable jobs in the queue, which causes PG to return no result.

Since job_count is factored into the value of relative_top, fixing its value to be the number of runnable jobs instead of the total number of jobs, will make a result to always be returned if it is available.