2017-07-09 13:49:52 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:40:03 -04:00
|
|
|
|
2016-08-06 12:40:07 -04:00
|
|
|
require "backburner"
|
2014-05-20 07:03:46 -04:00
|
|
|
|
|
|
|
module ActiveJob
|
|
|
|
module QueueAdapters
|
2014-09-21 16:20:23 -04:00
|
|
|
# == Backburner adapter for Active Job
|
|
|
|
#
|
|
|
|
# Backburner is a beanstalkd-powered job queue that can handle a very
|
|
|
|
# high volume of jobs. You create background jobs and place them on
|
|
|
|
# multiple work queues to be processed later. Read more about
|
|
|
|
# Backburner {here}[https://github.com/nesquena/backburner].
|
|
|
|
#
|
|
|
|
# To use Backburner set the queue_adapter config to +:backburner+.
|
|
|
|
#
|
|
|
|
# Rails.application.config.active_job.queue_adapter = :backburner
|
2014-05-20 07:03:46 -04:00
|
|
|
class BackburnerAdapter
|
2015-03-11 17:57:13 -04:00
|
|
|
def enqueue(job) #:nodoc:
|
2018-09-08 00:55:05 -04:00
|
|
|
Backburner::Worker.enqueue(JobWrapper, [job.serialize], queue: job.queue_name, pri: job.priority)
|
2015-03-11 17:57:13 -04:00
|
|
|
end
|
2014-05-20 12:13:28 -04:00
|
|
|
|
2015-03-11 17:57:13 -04:00
|
|
|
def enqueue_at(job, timestamp) #:nodoc:
|
|
|
|
delay = timestamp - Time.current.to_f
|
2018-09-08 00:55:05 -04:00
|
|
|
Backburner::Worker.enqueue(JobWrapper, [job.serialize], queue: job.queue_name, pri: job.priority, delay: delay)
|
2014-05-20 18:26:19 -04:00
|
|
|
end
|
2014-05-20 07:03:46 -04:00
|
|
|
|
2014-09-17 15:46:53 -04:00
|
|
|
class JobWrapper #:nodoc:
|
2014-05-20 07:03:46 -04:00
|
|
|
class << self
|
2014-08-25 10:34:50 -04:00
|
|
|
def perform(job_data)
|
|
|
|
Base.execute job_data
|
2014-05-20 07:03:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|