aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/lib/active_job/queue_adapters/backburner_adapter.rb
blob: e1b00f1de770e1590592e4ea1e2b07b6408b4990 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
        class << self
          def perform(job_data)
            Base.execute job_data
          end
        end
      end
    end
  end
end