diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/active_job/base.rb | 10 | ||||
-rw-r--r-- | lib/active_job/job_wrappers/resque_wrapper.rb | 37 | ||||
-rw-r--r-- | lib/active_job/queue_adapters/resque_adapter.rb | 3 |
3 files changed, 47 insertions, 3 deletions
diff --git a/lib/active_job/base.rb b/lib/active_job/base.rb index e18c9d4309..341ea6158b 100644 --- a/lib/active_job/base.rb +++ b/lib/active_job/base.rb @@ -3,12 +3,18 @@ require 'active_job/queue_adapters/resque_adapter' module ActiveJob class Base - cattr_accessor(:queue_adapter) { ActiveJob::QueueAdapters::InlineAdapter } - + cattr_accessor(:queue_adapter) { ActiveJob::QueueAdapters::InlineAdapter } + cattr_accessor(:queue_base_name) { "active_jobs" } + cattr_accessor(:queue_name) { queue_base_name } + class << self def enqueue(*args) queue_adapter.queue self, *args end + + def queue_as(part_name) + self.queue_name = "#{queue_base_name}_#{part_name}" + end end end end
\ No newline at end of file diff --git a/lib/active_job/job_wrappers/resque_wrapper.rb b/lib/active_job/job_wrappers/resque_wrapper.rb new file mode 100644 index 0000000000..c34ea99f3c --- /dev/null +++ b/lib/active_job/job_wrappers/resque_wrapper.rb @@ -0,0 +1,37 @@ +require 'resque' + +require 'active_support/core_ext/enumerable' +require 'active_support/core_ext/array/access' +require 'active_support/core_ext/string/inflections' + + +module ActiveJob + module JobWrappers + class ResqueWrapper + class << self + def wrap(job, args) + [ new(job), *args.prepend(job) ] + end + + def perform(*args) + unwrapped_job = args.first.constantize + + if args.many? + unwrapped_job.perform *args.from(1) + else + unwrapped_job.perform + end + end + end + + + def initialize(job) + @queue = job.queue_name + end + + def to_s + self.class.to_s + end + end + end +end
\ No newline at end of file diff --git a/lib/active_job/queue_adapters/resque_adapter.rb b/lib/active_job/queue_adapters/resque_adapter.rb index 4155cd5bf9..43a44d2a48 100644 --- a/lib/active_job/queue_adapters/resque_adapter.rb +++ b/lib/active_job/queue_adapters/resque_adapter.rb @@ -1,11 +1,12 @@ require 'resque' +require 'active_job/job_wrappers/resque_wrapper' module ActiveJob module QueueAdapters class ResqueAdapter class << self def queue(job, *args) - Resque.enqueue(job, *args) + Resque.enqueue *JobWrappers::ResqueWrapper.wrap(job, args) end end end |