php-resque icon indicating copy to clipboard operation
php-resque copied to clipboard

Can't clear a queue from the code

Open blood73 opened this issue 8 years ago • 2 comments

I want to clear queued jobs. I tried this:

$queued_jobs = Resque\Redis::instance()->lrange('queue:eaisto', 0, -1);
if (!empty($queued_jobs) && count($queued_jobs) >= MAX_QUEUE_COUNT) {
    foreach ($queued_jobs as $job) {
        $payload = json_decode($job, true);
        if (!empty($payload['id'])) {
            $job_object = Resque\Job::load($payload['id']);
            $job_object->cancel();
        }
    }
}

But this code copied jobs to cancel only. List of queued jobs didn't cleared:

Eaisto queue queued jobs: 
	1.  {"id":"cb6ecf0c16157704296a99","class":"GibddJob","data":["\u0415953\u0421\u041073",false]}
	2.  {"id":"cb6ecf0c161577043cf94b","class":"GibddJob","data":["\u0415953\u0421\u041073",false]}
	3.  {"id":"cb6ecf0c161577044d4dea","class":"GibddJob","data":["\u0415953\u0421\u041073",false]}

Eaisto queue cancelled jobs: 
	1. {"id":"cb6ecf0c161577044d4dea","class":"GibddJob","data":["\u0415953\u0421\u041073",false]}
	2. {"id":"cb6ecf0c161577043cf94b","class":"GibddJob","data":["\u0415953\u0421\u041073",false]}
	3. {"id":"cb6ecf0c16157704296a99","class":"GibddJob","data":["\u0415953\u0421\u041073",false]}

What is wrong with this code? How I can clear a list of queued jobs? (not from running job)

blood73 avatar Feb 03 '18 09:02 blood73

+1

uxieme avatar Mar 27 '18 11:03 uxieme

    $queues = 'my:queue';
    while (false !== ($job = Resque::pop((new Resque\Worker($queues, false))->resolveQueues(), 0, false))) {
         Stats::decr('queued', 1);
         Stats::decr('queued', 1, Queue::redisKey($job->getQueue(), 'stats'));
        $job->cancel();
    }

MiRacLe-RPZ avatar Mar 19 '21 08:03 MiRacLe-RPZ