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-08-01 16:55:16 -04:00
|
|
|
|
2014-07-03 12:44:01 -04:00
|
|
|
begin
|
|
|
|
require 'resque-scheduler'
|
2014-08-01 19:56:38 -04:00
|
|
|
rescue LoadError
|
|
|
|
begin
|
|
|
|
require 'resque_scheduler'
|
2014-08-16 08:49:03 -04:00
|
|
|
rescue LoadError
|
|
|
|
false
|
2014-08-01 19:56:38 -04:00
|
|
|
end
|
2014-07-03 12:44:01 -04:00
|
|
|
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-08-16 08:49:03 -04:00
|
|
|
unless Resque.respond_to?(:enqueue_at_with_queue)
|
|
|
|
raise NotImplementedError, "To be able to schedule jobs with Resque you need the " \
|
|
|
|
"resque-scheduler gem. Please add it to your Gemfile and run bundle install"
|
|
|
|
end
|
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-08-18 09:09:04 -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
|