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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With