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-07-03 12:44:01 -04:00
|
|
|
begin
|
|
|
|
require 'resque-scheduler'
|
|
|
|
rescue LoadError
|
|
|
|
require 'resque_scheduler'
|
|
|
|
end
|
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-30 19:19:30 -04:00
|
|
|
Resque.enqueue_to job.queue_name, JobWrapper, job.name, *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-30 19:19:30 -04:00
|
|
|
Resque.enqueue_at_with_queue job.queue_name, timestamp, JobWrapper, job.name, *args
|
2014-05-19 18:27:28 -04:00
|
|
|
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
|
2014-05-18 06:32:22 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-05-19 08:00:14 -04:00
|
|
|
end
|