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

Adds additional rake task to clear jobs from a specific queue #978

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

azeezahmed
Copy link

Currently, the 'jobs:clear' task clears all the records from the delayed_job table however, there will be scenarios where jobs only from a specific queue need to be cleared.

ex: restarting (post-maintenance) you would only want to clear WebSocket jobs (news feed) but not subscription charges job (monthly billing).

this pull request adds an additional rake task that accepts a parameter(queue_name) and clears the jobs from the queue.

@coveralls
Copy link

coveralls commented May 11, 2017

Coverage Status

Coverage remained the same at 90.934% when pulling d4f404d on azeezahmed:master into bd07783 on collectiveidea:master.

@kou
Copy link

kou commented Aug 5, 2019

I want this feature too but this implementation isn't suitable.
Because it works only with Active Record backend.

We need to add a new backend API such as Delayed::Job.delete_all(queues: nil) and Delayed::Job.delete_queues(queues) to make this feature portable.

And I think that we don't need to add a new task. We can reuse jobs:clear task like the following:

diff --git a/lib/delayed/tasks.rb b/lib/delayed/tasks.rb
index 409ba48..edacb18 100644
--- a/lib/delayed/tasks.rb
+++ b/lib/delayed/tasks.rb
@@ -1,7 +1,12 @@
 namespace :jobs do
   desc 'Clear the delayed_job queue.'
   task :clear => :environment do
-    Delayed::Job.delete_all
+    queues = (ENV['QUEUES'] || ENV['QUEUE'] || '').split(',')
+    if queues.present?
+      Delayed::Job.delete_queue(queues)
+    else
+      Delayed::Job.delete_all
+    end
   end
 
   desc 'Start a delayed_job worker.'

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

Successfully merging this pull request may close these issues.

None yet

3 participants