1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activejob/lib/active_job/queue_adapters/qu_adapter.rb

43 lines
1.2 KiB
Ruby
Raw Normal View History

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.
#
# 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|
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
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