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/queue_classic_adapter.rb

55 lines
2 KiB
Ruby
Raw Normal View History

2014-05-19 17:01:56 -04:00
require 'queue_classic'
module ActiveJob
module QueueAdapters
2014-10-06 11:58:45 -04:00
# == queue_classic adapter for Active Job
2014-09-21 16:20:23 -04:00
#
# queue_classic provides a simple interface to a PostgreSQL-backed message
# queue. queue_classic specializes in concurrent locking and minimizing
# database load while providing a simple, intuitive developer experience.
# queue_classic assumes that you are already using PostgreSQL in your
# production environment and that adding another dependency (e.g. redis,
# beanstalkd, 0mq) is undesirable.
#
2014-10-06 11:58:45 -04:00
# Read more about queue_classic {here}[https://github.com/QueueClassic/queue_classic].
2014-09-21 16:20:23 -04:00
#
2014-10-06 11:58:45 -04:00
# To use queue_classic set the queue_adapter config to +:queue_classic+.
2014-09-21 16:20:23 -04:00
#
# Rails.application.config.active_job.queue_adapter = :queue_classic
2014-05-19 17:01:56 -04:00
class QueueClassicAdapter
class << self
2014-09-21 16:20:23 -04:00
def enqueue(job) #:nodoc:
2014-08-25 10:34:50 -04:00
build_queue(job.queue_name).enqueue("#{JobWrapper.name}.perform", job.serialize)
2014-05-19 17:01:56 -04:00
end
2014-09-21 16:20:23 -04:00
def enqueue_at(job, timestamp) #:nodoc:
queue = build_queue(job.queue_name)
unless queue.respond_to?(:enqueue_at)
2014-10-06 11:58:45 -04:00
raise NotImplementedError, 'To be able to schedule jobs with queue_classic ' \
'the QC::Queue needs to respond to `enqueue_at(timestamp, method, *args)`. ' \
'You can implement this yourself or you can use the queue_classic-later gem.'
end
2014-08-25 10:34:50 -04:00
queue.enqueue_at(timestamp, "#{JobWrapper.name}.perform", job.serialize)
end
# Builds a <tt>QC::Queue</tt> object to schedule jobs on.
#
2014-09-27 07:21:29 -04:00
# If you have a custom <tt>QC::Queue</tt> subclass you'll need to subclass
# <tt>ActiveJob::QueueAdapters::QueueClassicAdapter</tt> and override the
# <tt>build_queue</tt> method.
def build_queue(queue_name)
QC::Queue.new(queue_name)
end
2014-05-19 17:01:56 -04:00
end
class JobWrapper #:nodoc:
class << self
2014-08-25 10:34:50 -04:00
def perform(job_data)
Base.execute job_data
end
2014-05-19 17:01:56 -04:00
end
end
end
end
end