Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't clear a queue from the code #87

Open
blood73 opened this issue Feb 3, 2018 · 2 comments
Open

Can't clear a queue from the code #87

blood73 opened this issue Feb 3, 2018 · 2 comments

Comments

@blood73
Copy link

blood73 commented Feb 3, 2018

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)

@uxieme
Copy link

uxieme commented Mar 27, 2018

+1

@MiRacLe-RPZ
Copy link
Contributor

MiRacLe-RPZ commented Mar 19, 2021

    $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();
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants