php-resque
php-resque copied to clipboard
Iterating failed jobs
Ruby Resque seems to have a way to iterate failed jobs on the Failure class (http://ariejan.net/2010/08/23/resque-how-to-requeue-failed-jobs/). What is the equivalent in phpresque? This is not for recreating jobs, just a way to iterate them.
By default (you can override it, with some work...), failed jobs are pushed to the failed
key (under whichever namespace prefix you've set Resque up to use). You can retrieve them using something like Resque::redis()->lrange('failed', 0, -1)
(for the full list; use 0, 1
to get only the first item, etc.).
As noted in the comments on the post you've linked above, the format of a failed job entry is different from that of a queued job. While queued jobs contain class
, args
, and id
keys, failed jobs have failed_at
, payload
, exception
, error
, backtrace
, worker
, and queue
. The original queued job contents (class
, args
, and id
) are in the payload
key.
There is currently no object-based interface for retrieving or requeueing failed jobs. This may change in a future release, but for the moment, that's all we have.