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 "que"
|
2014-05-19 14:09:45 -04:00
|
|
|
|
|
|
|
module ActiveJob
|
|
|
|
module QueueAdapters
|
2014-09-21 16:20:23 -04:00
|
|
|
# == Que adapter for Active Job
|
|
|
|
#
|
|
|
|
# Que is a high-performance alternative to DelayedJob or QueueClassic that
|
|
|
|
# improves the reliability of your application by protecting your jobs with
|
|
|
|
# the same ACID guarantees as the rest of your data. Que is a queue for
|
|
|
|
# Ruby and PostgreSQL that manages jobs using advisory locks.
|
|
|
|
#
|
|
|
|
# Read more about Que {here}[https://github.com/chanks/que].
|
|
|
|
#
|
|
|
|
# To use Que set the queue_adapter config to +:que+.
|
|
|
|
#
|
|
|
|
# Rails.application.config.active_job.queue_adapter = :que
|
2014-05-19 14:09:45 -04:00
|
|
|
class QueAdapter
|
2015-03-11 17:57:13 -04:00
|
|
|
def enqueue(job) #:nodoc:
|
2015-03-18 05:48:26 -04:00
|
|
|
que_job = JobWrapper.enqueue job.serialize, priority: job.priority
|
2015-05-07 11:25:49 -04:00
|
|
|
job.provider_job_id = que_job.attrs["job_id"]
|
|
|
|
que_job
|
2015-03-11 17:57:13 -04:00
|
|
|
end
|
2014-05-20 11:44:00 -04:00
|
|
|
|
2015-03-11 17:57:13 -04:00
|
|
|
def enqueue_at(job, timestamp) #:nodoc:
|
2015-03-18 05:48:26 -04:00
|
|
|
que_job = JobWrapper.enqueue job.serialize, priority: job.priority, run_at: Time.at(timestamp)
|
2015-05-07 11:25:49 -04:00
|
|
|
job.provider_job_id = que_job.attrs["job_id"]
|
|
|
|
que_job
|
2014-05-19 14:09:45 -04:00
|
|
|
end
|
|
|
|
|
2014-09-17 15:46:53 -04:00
|
|
|
class JobWrapper < Que::Job #:nodoc:
|
2014-08-25 10:34:50 -04:00
|
|
|
def run(job_data)
|
|
|
|
Base.execute job_data
|
2014-05-19 14:09:45 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|