Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear sidekiq queue

I've this worker that runs for ever.

class Worker   include Sidekiq::Worker   sidekiq_options queue: "infinity", retry: true    def perform(params)     # ...     self.class.perform_in(30.seconds, params)   end end 

The problem is that I load workers on start up, like this. config/initializers/load_workers.rb

Rails.application.config.after_initialize do     if ENV["SIDEKIQ"] == "1"     Worker.perform_async({})   end end 

Using this to start sidekiq SIDEKIQ=1 sidekiq --verbose --environment production -C config/sidekiq.yml.

This means that old workers as to stop, both those currently running but also the ones being rescheduled.

I tried running this on start up (just before loading new works), but that didn't work.

q = [] q += Sidekiq::RetrySet.new.select { |job| job.klass.match(/Worker/) } q += Sidekiq::Queue.new("infinity").select { |job| job.klass.match(/Worker/) } q += Sidekiq::ScheduledSet.new.select { |job| job.klass.match(/Worker/) } q.each(&:delete) 

After 5-ish deploys there are bunch of duplicate workers in the queue scheduled for later. So, is there a way to clear everyting in one queue and prevent already running jobs from rescheduling?

I'm using sidekiq 3.0.

like image 691
Linus Oleander Avatar asked Apr 17 '14 21:04

Linus Oleander


1 Answers

Deletes all Jobs in a Queue, by removing the queue.

require 'sidekiq/api' # for the case of rails console  Sidekiq::Queue.new("infinity").clear Sidekiq::RetrySet.new.clear Sidekiq::ScheduledSet.new.clear 
like image 124
Ranjithkumar Ravi Avatar answered Sep 26 '22 06:09

Ranjithkumar Ravi