title: Clear sidekiq queue
body: <p>I've this worker that runs for ever.</p>
  
  <pre><code>class Worker
    include Sidekiq::Worker
    sidekiq_options queue: "infinity", retry: true
  
    def perform(params)
      # ...
      self.class.perform_in(30.seconds, params)
    end
  end
  </code></pre>
  
  <p>The problem is that I load workers on start up, like this. <code>config/initializers/load_workers.rb</code></p>
  
  <pre><code>Rails.application.config.after_initialize do  
    if ENV["SIDEKIQ"] == "1"
      Worker.perform_async({})
    end
  end
  </code></pre>
  
  <p>Using this to start sidekiq <code>SIDEKIQ=1 sidekiq --verbose --environment production -C config/sidekiq.yml</code>.</p>
  
  <p>This means that old workers as to stop, both those currently running but also the ones being rescheduled.</p>
  
  <p>I tried running this on start up (just before loading new works), but that didn't work.</p>
  
  <pre><code>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(&amp;:delete)
  </code></pre>
  
  <p>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?</p>
  
  <p>I'm using sidekiq 3.0.</p>