rq / rq-scheduler

A lightweight library that adds job scheduling capabilities to RQ (Redis Queue)
MIT License
1.45k stars 230 forks source link

Scheduler cancelling all jobs in all queues when specific queue name was supposed to cancel #275

Open munzzz5 opened 2 years ago

munzzz5 commented 2 years ago

I am trying to schedule the main jobs in the default queue, But secondary jobs in another queue called "systemTriggers". The Job is scheduled in the second queue. when i cancel jobs in "systemTriggers" all jobs of default queue are also cancelled.

Here is how im doing this:

scheduler = Scheduler("systemTriggers",connection=Redis())
allJobs=scheduler.get_jobs()
for job in allJobs:
      scheduler.cancel(job)
scheduler.scheduler(newJob) # this is to avoid duplication whenever my django reloads as this is startup code

Thanks!

emuccino commented 2 years ago

I'm facing the same issue. My workaround is to filter jobs by the queue_name stored in the origin property. Here's how it would work using @munzzz5 example:

scheduler = Scheduler("systemTriggers",connection=Redis())
allJobs=scheduler.get_jobs()
for job in allJobs:
      if job.origin == "systemTriggers": # check that the job is from the desired queue
              scheduler.cancel(job)
scheduler.scheduler(newJob)