nvie/rq — pull request #173 by yaniv-aknin (2013-01-26 21:23:40+00:00)
Title: Worker TTL

These two commits implement part of what we discussed in issue [138](https://github.com/nvie/rq/issues/138).

Basically, these commits:

1. Make `dequeue_any` receive a more flexible `timeout` parameter rather than just a `blocking` flag
2. Set a timeout of `DEFAULT_WORKER_TTL` seconds on the worker key (by default, 420 seconds)
3. When idling and blocking on dequeuing a job, uses the augmented `dequeue_any` to only block for `DEFAULT_WORKER_TTL - 60` seconds; every time the dequeue times out, refreshes the TTL back to `DEFAULT_WORKER_TTL`
4. When taking a job, sets the worker TTL to `(job.timeout or 180) + 60.
5. When finishing a job, sets the worker TTL back to `DEFAULT_WORKER_TTL`.
6. Add a very basic test that the TTL is actually set. I think a bit of a refactor for `work()` is needed before deeper tests can be written; IMHO, `work()` does too much for a single function at this time.

I think this is good to merge, but didn't test it on a real environment beyond playing a bit with the new code.