2014-06-12 04:14:42 -04:00
|
|
|
require 'qu'
|
|
|
|
|
|
|
|
module ActiveJob
|
|
|
|
module QueueAdapters
|
2014-09-21 16:20:23 -04:00
|
|
|
# == Qu adapter for Active Job
|
|
|
|
#
|
|
|
|
# Qu is a Ruby library for queuing and processing background jobs. It is
|
|
|
|
# heavily inspired by delayed_job and Resque. Qu was created to overcome
|
2014-09-27 07:21:29 -04:00
|
|
|
# some shortcomings in the existing queuing libraries.
|
2014-09-21 16:20:23 -04:00
|
|
|
# The advantages of Qu are: Multiple backends (redis, mongo), jobs are
|
|
|
|
# requeued when worker is killed, resque-like API.
|
|
|
|
#
|
2014-09-27 10:22:15 -04:00
|
|
|
# Read more about Qu {here}[https://github.com/bkeepers/qu].
|
2014-09-21 16:20:23 -04:00
|
|
|
#
|
|
|
|
# To use Qu set the queue_adapter config to +:qu+.
|
|
|
|
#
|
|
|
|
# Rails.application.config.active_job.queue_adapter = :qu
|
2014-06-12 04:14:42 -04:00
|
|
|
class QuAdapter
|
|
|
|
class << self
|
2014-09-21 16:20:23 -04:00
|
|
|
def enqueue(job, *args) #:nodoc:
|
2014-08-25 10:34:50 -04:00
|
|
|
Qu::Payload.new(klass: JobWrapper, args: [job.serialize]).tap do |payload|
|
2014-08-06 17:09:28 -04:00
|
|
|
payload.instance_variable_set(:@queue, job.queue_name)
|
|
|
|
end.push
|
2014-06-12 04:14:42 -04:00
|
|
|
end
|
|
|
|
|
2014-09-21 16:20:23 -04:00
|
|
|
def enqueue_at(job, timestamp, *args) #:nodoc:
|
2014-06-12 04:14:42 -04:00
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-17 15:46:53 -04:00
|
|
|
class JobWrapper < Qu::Job #:nodoc:
|
2014-08-25 10:34:50 -04:00
|
|
|
def initialize(job_data)
|
|
|
|
@job_data = job_data
|
2014-06-12 04:14:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def perform
|
2014-08-25 10:34:50 -04:00
|
|
|
Base.execute @job_data
|
2014-06-12 04:14:42 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|