Skip to content

Instantly share code, notes, and snippets.

@MarceloCajueiro
Created July 17, 2018 11:50
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarceloCajueiro/64bdc429c579a34abb64f4cdc82f4b30 to your computer and use it in GitHub Desktop.
Save MarceloCajueiro/64bdc429c579a34abb64f4cdc82f4b30 to your computer and use it in GitHub Desktop.
Move sidekiq jobs from one queue to another
queue = Sidekiq::Queue.new("default")
queue.each do |job|
if job.klass == "DailyFrequencyCreatorWorker"
DailyFrequencyCreatorWorker.set(queue: 'daily_frequency_creator').perform_async(*job.args)
job.delete
end
end;nil
@josef-krabath
Copy link

Nice, thanks! 👍

@sharkey11
Copy link

Thanks!

@aray167
Copy link

aray167 commented Dec 13, 2022

b6104337420568469^uyutyut/
6104337420568469

=25021008213095117860
016104337420568469==443

@max2320
Copy link

max2320 commented Mar 13, 2024

This was very helpful, I did an improvement for my use case and would like to share here

def move_jobs(origin_queue, destination_queue, job_class, interval = 0.3,  reschedule = true)
  queue = Sidekiq::Queue.new(origin_queue)
  index = 1
  queue.each do |job|
    if job.klass == job_class
      new_job = if reschedule
        job_class.constantize.set(queue: destination_queue).perform_in((index * interval).seconds, *job.args)
      end
      job.delete
      puts "#{origin_queue}:#{job.jid} >> #{destination_queue}:#{new_job}" 
      index += 1
    end
  end

  index
end

move_jobs('default', 'daily_frequency_creator', 'DailyFrequencyCreatorWorker', 0.01)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment