2014-05-18 07:11:00 -04:00
|
|
|
require 'resque'
|
2014-05-19 06:34:27 -04:00
|
|
|
require 'active_support/core_ext/enumerable'
|
|
|
|
require 'active_support/core_ext/array/access'
|
2014-05-19 18:27:28 -04:00
|
|
|
require 'resque_scheduler'
|
2014-05-18 07:11:00 -04:00
|
|
|
|
2014-05-18 06:32:22 -04:00
|
|
|
module ActiveJob
|
|
|
|
module QueueAdapters
|
2014-05-18 07:11:00 -04:00
|
|
|
class ResqueAdapter
|
2014-05-18 06:32:22 -04:00
|
|
|
class << self
|
2014-05-20 19:07:45 -04:00
|
|
|
def enqueue(job, *args)
|
2014-05-19 08:00:14 -04:00
|
|
|
Resque.enqueue JobWrapper.new(job), job, *args
|
2014-05-19 06:34:27 -04:00
|
|
|
end
|
2014-05-19 18:27:28 -04:00
|
|
|
|
2014-05-20 19:07:45 -04:00
|
|
|
def enqueue_at(job, timestamp, *args)
|
2014-05-19 18:27:28 -04:00
|
|
|
Resque.enqueue_at timestamp, JobWrapper.new(job), job, *args
|
|
|
|
end
|
2014-05-19 06:34:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class JobWrapper
|
|
|
|
class << self
|
|
|
|
def perform(job_name, *args)
|
2014-05-22 14:37:06 -04:00
|
|
|
job_name.constantize.new.execute *args
|
2014-05-19 06:34:27 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(job)
|
|
|
|
@queue = job.queue_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
2014-05-19 08:00:14 -04:00
|
|
|
self.class.name
|
2014-05-18 06:32:22 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-05-19 08:00:14 -04:00
|
|
|
end
|