aboutsummaryrefslogblamecommitdiffstats
path: root/lib/active_job/queue_adapters/sidekiq_adapter.rb
blob: f738a7d91c477a49ae492dc40a7c259ef3221dbe (plain) (tree)
1
2
3
4
5
6
7
8
                 




                        
                               
                                                           




                                      
           
 
                                             



                                      

                                
           





                                    
                                                




           
require 'sidekiq'

module ActiveJob
  module QueueAdapters
    class SidekiqAdapter
      class << self
        def enqueue(job, *args)
          #Sidekiq::Client does not support symbols as keys
          Sidekiq::Client.push \
            'class' => JobWrapper,
            'queue' => job.queue_name,
            'args'  => [ job, *args ],
            'retry' => true
        end

        def enqueue_at(job, timestamp, *args)
          Sidekiq::Client.push \
            'class' => JobWrapper,
            'queue' => job.queue_name,
            'args'  => [ job, *args ],
            'retry' => true,
            'at'    => timestamp
        end
      end

      class JobWrapper
        include Sidekiq::Worker

        def perform(job_name, *args)
          job_name.constantize.new.execute *args
        end
      end
    end
  end
end