1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activejob/lib/active_job/queue_adapters/resque_adapter.rb

42 lines
1 KiB
Ruby
Raw Normal View History

require 'resque'
2014-05-19 06:34:27 -04:00
require 'active_support/core_ext/enumerable'
require 'active_support/core_ext/array/access'
begin
require 'resque-scheduler'
rescue LoadError
begin
require 'resque_scheduler'
rescue LoadError
false
end
end
2014-05-18 06:32:22 -04:00
module ActiveJob
module QueueAdapters
class ResqueAdapter
2014-05-18 06:32:22 -04:00
class << self
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
def enqueue_at(job, timestamp, *args)
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
end
2014-05-19 06:34:27 -04:00
end
class JobWrapper
class << self
def perform(job_name, *args)
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
end