public static function cleanup(array $queues = array('*'))
{
$cleaned = array('zombie' => 0, 'processed' => 0);
$redis = Redis::instance();
if (in_array('*', $queues)) {
$queues = (array) $redis->smembers(Queue::redisKey());
sort($queues);
}
$workers = $redis->smembers(Worker::redisKey());
foreach ($queues as $queue) {
$jobs = $redis->zrangebyscore(Queue::redisKey($queue, 'running'), 0, time());
foreach ($jobs as $payload) {
$job = self::loadPayload($queue, $payload);
$packet = $job->getPacket();
if (!in_array($packet['worker'], $workers)) {
$job->fail(new Exception\Zombie());
$cleaned['zombie']++;
}
}
$cleaned['processed'] = $redis->zremrangebyscore(Queue::redisKey($queue, 'processed'), 0, time() - \Resque::getConfig('default.expiry_time', \Resque::DEFAULT_EXPIRY_TIME));
}
return $cleaned;
}