chrisboulton / php-resque

PHP port of resque (Workers and Queueing)
MIT License
3.43k stars 759 forks source link

How to push Failed Jobs into queue using PHP Script #251

Open arunp27 opened 9 years ago

arunp27 commented 9 years ago

Hi, How can we know if a job is failed.. if the job is failed how to push into the queue using php script. and i've one more question how to restart workers programmatically.

danhunsaker commented 9 years ago
  1. Failed jobs can be found by checking the job's status, or by using the onFailure event.
  2. Failed jobs are pushed onto a Redis list called {$prefix}:failed - you can pop them from there and push them (back) onto whatever queue you like using the normal methods.
  3. Restarting workers isn't simple. You can kill them programmatically easily enough using signals, but spawning a new one requires a monitoring script or tool of some kind.
zspine commented 9 years ago

@danhunsaker I am using the php-resque in a production app and php-resque heavily used on all 3rd party web service api calls. Yesterday I noticed some failed jobs by running the below code

//https://github.com/chrisboulton/php-resque/issues/171

$list = $redis->lrange('failed', 0, -1);

now am trying to requeue the failed jobs by following the instruction above and it seems to be working fine. but only the problem is, I cannot remove the elements from failed list.

foreach($list as $row) {
    $row    = json_decode($row);
    $job    = $row->payload;
    $queue  = $row->queue;
    Resque::enqueue($queue, $job->class, $job->args);
}

I tried the php $redis->lTrim('failed'); inside the loop but it does not seems to be working :( any help greatly appreciated...

and also it would be great to have a feature for requeue a failed job

zspine commented 9 years ago

finally found the solution:

$redis->lpop('failed'); //removes and returns the first element