Cleaner queuing of jobs using Delayed Job

This commit is contained in:
David Genord II 2014-09-18 15:52:30 -04:00
parent 25f5af7f3f
commit 0b10565d96
1 changed files with 9 additions and 3 deletions

View File

@ -5,16 +5,22 @@ module ActiveJob
class DelayedJobAdapter
class << self
def enqueue(job)
JobWrapper.new.delay(queue: job.queue_name).perform(job.serialize)
Delayed::Job.enqueue(JobWrapper.new(job.serialize), queue: job.queue_name)
end
def enqueue_at(job, timestamp)
JobWrapper.new.delay(queue: job.queue_name, run_at: Time.at(timestamp)).perform(job.serialize)
Delayed::Job.enqueue(JobWrapper.new(job.serialize), queue: job.queue_name, run_at: Time.at(timestamp))
end
end
class JobWrapper #:nodoc:
def perform(job_data)
attr_accessor :job_data
def initialize(job_data)
@job_data = job_data
end
def perform
Base.execute(job_data)
end
end