Created
          July 17, 2018 11:50 
        
      - 
      
 - 
        
Save MarceloCajueiro/64bdc429c579a34abb64f4cdc82f4b30 to your computer and use it in GitHub Desktop.  
    Move sidekiq jobs from one queue to another
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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 | 
b6104337420568469^uyutyut/
6104337420568469
=25021008213095117860
016104337420568469==443
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
  
            
Thanks!