seatgeek/djjob — pull request #14 by alexdean (2011-12-21 15:23:22+00:00)
Title: configurable retry delay in DJRetryException

Patch allows code like: `throw new DJJobException('Exception message.', 5);`, meaning try the job again in 5 seconds. 2nd argument is optional. If omitted, the default is the same as current DJJob behavior (2 hour delay).

In current DJJob, jobs can be scheduled for retry even if that retry would exceed `max_attempts`. A job like this will sit in the queue forever since the selection logic will see it's been tried too many times, but the job won't be failed. This patch also resolves that issue by failing a job which has hit its `max_attempts` value through retries.

Worker log output looks like:

2011-12-21 15:15:43 [JOB] Starting worker host::dev.ted.com pid::18181 on queue::default
2011-12-21 15:15:43 [JOB] attempting to acquire lock for job::12 on host::dev.ted.com pid::18181
2011-12-21 15:15:43 [JOB] job::12 Caught DJRetryException 'Exception message.' on attempt 1/3. Try again in 5 seconds.
2011-12-21 15:15:48 [JOB] attempting to acquire lock for job::12 on host::dev.ted.com pid::18181
2011-12-21 15:15:48 [JOB] job::12 Caught DJRetryException 'Exception message.' on attempt 2/3. Try again in 5 seconds.
2011-12-21 15:15:53 [JOB] attempting to acquire lock for job::12 on host::dev.ted.com pid::18181
2011-12-21 15:15:53 [JOB] job::12 Caught DJRetryException 'Exception message.' on attempt 3/3. Giving up.
2011-12-21 15:15:53 [JOB] failure in job::12