mirror of https://github.com/rails/rails
Cleaner queuing of jobs using Delayed Job
This commit is contained in:
parent
25f5af7f3f
commit
0b10565d96
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue