From 501cc60ff2528ba75c0bf0715918516864546539 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 19 May 2014 12:34:27 +0200 Subject: Inline the job wrappers --- lib/active_job/job_wrappers/delayed_job_wrapper.rb | 9 ------- lib/active_job/job_wrappers/resque_wrapper.rb | 29 ---------------------- lib/active_job/job_wrappers/sidekiq_wrapper.rb | 13 ---------- .../job_wrappers/sucker_punch_wrapper.rb | 11 -------- .../queue_adapters/delayed_job_adapter.rb | 9 +++++-- lib/active_job/queue_adapters/resque_adapter.rb | 25 +++++++++++++++++-- lib/active_job/queue_adapters/sidekiq_adapter.rb | 11 ++++++-- .../queue_adapters/sucker_punch_adapter.rb | 11 ++++++-- 8 files changed, 48 insertions(+), 70 deletions(-) delete mode 100644 lib/active_job/job_wrappers/delayed_job_wrapper.rb delete mode 100644 lib/active_job/job_wrappers/resque_wrapper.rb delete mode 100644 lib/active_job/job_wrappers/sidekiq_wrapper.rb delete mode 100644 lib/active_job/job_wrappers/sucker_punch_wrapper.rb diff --git a/lib/active_job/job_wrappers/delayed_job_wrapper.rb b/lib/active_job/job_wrappers/delayed_job_wrapper.rb deleted file mode 100644 index 0868d7b570..0000000000 --- a/lib/active_job/job_wrappers/delayed_job_wrapper.rb +++ /dev/null @@ -1,9 +0,0 @@ -module ActiveJob - module JobWrappers - class DelayedJobWrapper - def perform(job, *args) - job.perform(*ActiveJob::Parameters.deserialize(args)) - end - end - end -end diff --git a/lib/active_job/job_wrappers/resque_wrapper.rb b/lib/active_job/job_wrappers/resque_wrapper.rb deleted file mode 100644 index 68d9b252ba..0000000000 --- a/lib/active_job/job_wrappers/resque_wrapper.rb +++ /dev/null @@ -1,29 +0,0 @@ -require 'resque' - -require 'active_support/core_ext/enumerable' -require 'active_support/core_ext/array/access' - -module ActiveJob - module JobWrappers - class ResqueWrapper - class << self - def wrap(job, args) - [ new(job), *args.prepend(job) ] - end - - def perform(job_name, *args) - job_name.constantize.perform(*ActiveJob::Parameters.deserialize(args)) - end - end - - - def initialize(job) - @queue = job.queue_name - end - - def to_s - self.class.to_s - end - end - end -end diff --git a/lib/active_job/job_wrappers/sidekiq_wrapper.rb b/lib/active_job/job_wrappers/sidekiq_wrapper.rb deleted file mode 100644 index e1332b0210..0000000000 --- a/lib/active_job/job_wrappers/sidekiq_wrapper.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'active_job/parameters' - -module ActiveJob - module JobWrappers - class SidekiqWrapper - include Sidekiq::Worker - - def perform(job_name, *args) - job_name.constantize.perform(*ActiveJob::Parameters.deserialize(args)) - end - end - end -end diff --git a/lib/active_job/job_wrappers/sucker_punch_wrapper.rb b/lib/active_job/job_wrappers/sucker_punch_wrapper.rb deleted file mode 100644 index 7e9960b44f..0000000000 --- a/lib/active_job/job_wrappers/sucker_punch_wrapper.rb +++ /dev/null @@ -1,11 +0,0 @@ -module ActiveJob - module JobWrappers - class SuckerPunchWrapper - include SuckerPunch::Job - - def perform(job_name, *args) - job_name.perform(*ActiveJob::Parameters.deserialize(args)) - end - end - end -end diff --git a/lib/active_job/queue_adapters/delayed_job_adapter.rb b/lib/active_job/queue_adapters/delayed_job_adapter.rb index 4730d97a9a..1db15f1804 100644 --- a/lib/active_job/queue_adapters/delayed_job_adapter.rb +++ b/lib/active_job/queue_adapters/delayed_job_adapter.rb @@ -1,12 +1,17 @@ require 'delayed_job' -require 'active_job/job_wrappers/delayed_job_wrapper' module ActiveJob module QueueAdapters class DelayedJobAdapter class << self def queue(job, *args) - JobWrappers::DelayedJobWrapper.new.delay(queue: job.queue_name).perform(job, *args) + JobWrapper.new.delay(queue: job.queue_name).perform(job, *args) + end + end + + class JobWrapper + def perform(job, *args) + job.perform(*ActiveJob::Parameters.deserialize(args)) end end end diff --git a/lib/active_job/queue_adapters/resque_adapter.rb b/lib/active_job/queue_adapters/resque_adapter.rb index 43a44d2a48..1d1f9ffe83 100644 --- a/lib/active_job/queue_adapters/resque_adapter.rb +++ b/lib/active_job/queue_adapters/resque_adapter.rb @@ -1,12 +1,33 @@ require 'resque' -require 'active_job/job_wrappers/resque_wrapper' +require 'active_support/core_ext/enumerable' +require 'active_support/core_ext/array/access' module ActiveJob module QueueAdapters class ResqueAdapter class << self def queue(job, *args) - Resque.enqueue *JobWrappers::ResqueWrapper.wrap(job, args) + Resque.enqueue *JobWrapper.wrap(job, args) + end + end + + class JobWrapper + class << self + def wrap(job, args) + [ new(job), *args.prepend(job) ] + end + + def perform(job_name, *args) + job_name.constantize.perform(*ActiveJob::Parameters.deserialize(args)) + end + end + + def initialize(job) + @queue = job.queue_name + end + + def to_s + self.class.to_s end end end diff --git a/lib/active_job/queue_adapters/sidekiq_adapter.rb b/lib/active_job/queue_adapters/sidekiq_adapter.rb index 70c4377a23..90af35525a 100644 --- a/lib/active_job/queue_adapters/sidekiq_adapter.rb +++ b/lib/active_job/queue_adapters/sidekiq_adapter.rb @@ -1,12 +1,19 @@ require 'sidekiq' -require 'active_job/job_wrappers/sidekiq_wrapper' module ActiveJob module QueueAdapters class SidekiqAdapter class << self def queue(job, *args) - JobWrappers::SidekiqWrapper.perform_async(job, *args) + JobWrapper.perform_async(job, *args) + end + end + + class JobWrapper + include Sidekiq::Worker + + def perform(job_name, *args) + job_name.constantize.perform(*ActiveJob::Parameters.deserialize(args)) end end end diff --git a/lib/active_job/queue_adapters/sucker_punch_adapter.rb b/lib/active_job/queue_adapters/sucker_punch_adapter.rb index 8191e5a1df..d721a0dcd5 100644 --- a/lib/active_job/queue_adapters/sucker_punch_adapter.rb +++ b/lib/active_job/queue_adapters/sucker_punch_adapter.rb @@ -1,12 +1,19 @@ require 'sucker_punch' -require 'active_job/job_wrappers/sucker_punch_wrapper' module ActiveJob module QueueAdapters class SuckerPunchAdapter class << self def queue(job, *args) - JobWrappers::SuckerPunchWrapper.new.async.perform(job, *args) + JobWrapper.new.async.perform(job, *args) + end + end + + class JobWrapper + include SuckerPunch::Job + + def perform(job_name, *args) + job_name.perform(*ActiveJob::Parameters.deserialize(args)) end end end -- cgit v1.2.3