aboutsummaryrefslogblamecommitdiffstats
path: root/activejob/lib/active_job/queue_adapters/backburner_adapter.rb
blob: a07a6fc223939d350fe454f97739f393ba874e76 (plain) (tree)
1
2
3
4
5
6
7
8
9





                           

                                                                                         
           
 
                                      
                                               
                                                                                                       
           
         
 
                               
                     

                                 





             
require 'backburner'

module ActiveJob
  module QueueAdapters
    class BackburnerAdapter
      class << self
        def enqueue(job)
          Backburner::Worker.enqueue JobWrapper, [ job.serialize ], queue: job.queue_name
        end

        def enqueue_at(job, timestamp)
          delay = timestamp - Time.current.to_f
          Backburner::Worker.enqueue JobWrapper, [ job.serialize ], queue: job.queue_name, delay: delay
        end
      end

      class JobWrapper #:nodoc:
        class << self
          def perform(job_data)
            Base.execute job_data
          end
        end
      end
    end
  end
end