malthe/pq

Should len(queue) skip items scheduled in the future?

Closed this issue · 1 comments

I’d like to use len(queue) to determine the size of a worker pool. Currently, Queue._count() returns the count of all tasks including those scheduled in the future. This is different from the number of tasks currently available for work.

Can or should len(queue) be modified to count only tasks available to a worker? The addition of one conditional to the WHERE clause should be sufficient:

SELECT COUNT(*) FROM %(table)s
WHERE q_name = %(name)s AND dequeued_at IS NULL
  AND (schedule_at IS NULL OR schedule_at <= NOW())

I think that's a very valid change, yes.