From 26dc3ea7b8ac770b8265fa8ce97ed67158cfb68a Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 22 May 2014 20:37:06 +0200 Subject: Rename #perform_with_hooks to #execution --- lib/active_job/base.rb | 4 ++-- lib/active_job/execution.rb | 26 ++++++++++++++++++++++ lib/active_job/performing.rb | 26 ---------------------- .../queue_adapters/backburner_adapter.rb | 2 +- .../queue_adapters/delayed_job_adapter.rb | 2 +- lib/active_job/queue_adapters/inline_adapter.rb | 4 ++-- lib/active_job/queue_adapters/que_adapter.rb | 2 +- .../queue_adapters/queue_classic_adapter.rb | 2 +- lib/active_job/queue_adapters/resque_adapter.rb | 2 +- lib/active_job/queue_adapters/sidekiq_adapter.rb | 2 +- lib/active_job/queue_adapters/sneakers_adapter.rb | 2 +- .../queue_adapters/sucker_punch_adapter.rb | 2 +- test/cases/callbacks_test.rb | 2 +- test/cases/rescue_test.rb | 2 +- 14 files changed, 40 insertions(+), 40 deletions(-) create mode 100644 lib/active_job/execution.rb delete mode 100644 lib/active_job/performing.rb diff --git a/lib/active_job/base.rb b/lib/active_job/base.rb index 1b88bc5bcc..27733577e4 100644 --- a/lib/active_job/base.rb +++ b/lib/active_job/base.rb @@ -1,7 +1,7 @@ require 'active_job/queue_adapter' require 'active_job/queue_name' require 'active_job/enqueuing' -require 'active_job/performing' +require 'active_job/execution' require 'active_job/logging' require 'active_job/callbacks' @@ -11,7 +11,7 @@ module ActiveJob extend QueueName include Enqueuing - include Performing + include Execution include Callbacks include Logging diff --git a/lib/active_job/execution.rb b/lib/active_job/execution.rb new file mode 100644 index 0000000000..563e42ff89 --- /dev/null +++ b/lib/active_job/execution.rb @@ -0,0 +1,26 @@ +require 'active_support/rescuable' +require 'active_job/arguments' + +module ActiveJob + module Execution + extend ActiveSupport::Concern + + included do + include ActiveSupport::Rescuable + end + + def execute(*serialized_args) + self.arguments = Arguments.deserialize(serialized_args) + + run_callbacks :perform do + perform *arguments + end + rescue => exception + rescue_with_handler(exception) + end + + def perform(*) + raise NotImplementedError + end + end +end diff --git a/lib/active_job/performing.rb b/lib/active_job/performing.rb deleted file mode 100644 index c3f57873e5..0000000000 --- a/lib/active_job/performing.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'active_support/rescuable' -require 'active_job/arguments' - -module ActiveJob - module Performing - extend ActiveSupport::Concern - - included do - include ActiveSupport::Rescuable - end - - def perform_with_hooks(*serialized_args) - self.arguments = Arguments.deserialize(serialized_args) - - run_callbacks :perform do - perform *arguments - end - rescue => exception - rescue_with_handler(exception) - end - - def perform(*) - raise NotImplementedError - end - end -end diff --git a/lib/active_job/queue_adapters/backburner_adapter.rb b/lib/active_job/queue_adapters/backburner_adapter.rb index b7e963cd6f..7a6032e56b 100644 --- a/lib/active_job/queue_adapters/backburner_adapter.rb +++ b/lib/active_job/queue_adapters/backburner_adapter.rb @@ -16,7 +16,7 @@ module ActiveJob class JobWrapper class << self def perform(job_name, *args) - job_name.constantize.new.perform_with_hooks *args + job_name.constantize.new.execute *args 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 fa08d779fb..c0561044be 100644 --- a/lib/active_job/queue_adapters/delayed_job_adapter.rb +++ b/lib/active_job/queue_adapters/delayed_job_adapter.rb @@ -15,7 +15,7 @@ module ActiveJob class JobWrapper def perform(job, *args) - job.new.perform_with_hooks *args + job.new.execute *args end end end diff --git a/lib/active_job/queue_adapters/inline_adapter.rb b/lib/active_job/queue_adapters/inline_adapter.rb index 8b82d7c25a..d116520285 100644 --- a/lib/active_job/queue_adapters/inline_adapter.rb +++ b/lib/active_job/queue_adapters/inline_adapter.rb @@ -3,7 +3,7 @@ module ActiveJob class InlineAdapter class << self def enqueue(job, *args) - job.new.perform_with_hooks *args + job.new.execute *args end def enqueue_at(job, timestamp, *args) @@ -11,7 +11,7 @@ module ActiveJob begin interval = Time.now.to_f - timestamp sleep(interval) if interval > 0 - job.new.perform_with_hooks *args + job.new.execute *args rescue => e ActiveJob::Base.logger.info "Error performing #{job}: #{e.message}" end diff --git a/lib/active_job/queue_adapters/que_adapter.rb b/lib/active_job/queue_adapters/que_adapter.rb index adb9125666..3d30b2bc72 100644 --- a/lib/active_job/queue_adapters/que_adapter.rb +++ b/lib/active_job/queue_adapters/que_adapter.rb @@ -15,7 +15,7 @@ module ActiveJob class JobWrapper < Que::Job def run(job, *args) - job.new.perform_with_hooks *args + job.new.execute *args end end end diff --git a/lib/active_job/queue_adapters/queue_classic_adapter.rb b/lib/active_job/queue_adapters/queue_classic_adapter.rb index 01d6d30caf..db7189f076 100644 --- a/lib/active_job/queue_adapters/queue_classic_adapter.rb +++ b/lib/active_job/queue_adapters/queue_classic_adapter.rb @@ -15,7 +15,7 @@ module ActiveJob class JobWrapper def self.perform(job, *args) - job.new.perform_with_hooks *args + job.new.execute *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 99da3c63ce..f7ed4669bd 100644 --- a/lib/active_job/queue_adapters/resque_adapter.rb +++ b/lib/active_job/queue_adapters/resque_adapter.rb @@ -19,7 +19,7 @@ module ActiveJob class JobWrapper class << self def perform(job_name, *args) - job_name.constantize.new.perform_with_hooks *args + job_name.constantize.new.execute *args end end diff --git a/lib/active_job/queue_adapters/sidekiq_adapter.rb b/lib/active_job/queue_adapters/sidekiq_adapter.rb index 2a2c2ce442..53e7b4d7fa 100644 --- a/lib/active_job/queue_adapters/sidekiq_adapter.rb +++ b/lib/active_job/queue_adapters/sidekiq_adapter.rb @@ -26,7 +26,7 @@ module ActiveJob include Sidekiq::Worker def perform(job_name, *args) - job_name.constantize.new.perform_with_hooks *args + job_name.constantize.new.execute *args end end end diff --git a/lib/active_job/queue_adapters/sneakers_adapter.rb b/lib/active_job/queue_adapters/sneakers_adapter.rb index ebd794fca1..3ca7745506 100644 --- a/lib/active_job/queue_adapters/sneakers_adapter.rb +++ b/lib/active_job/queue_adapters/sneakers_adapter.rb @@ -23,7 +23,7 @@ module ActiveJob include Sneakers::Worker def work(job, *args) - job.new.perform_with_hooks *args + job.new.execute *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 a166081f9f..64b9c3ca15 100644 --- a/lib/active_job/queue_adapters/sucker_punch_adapter.rb +++ b/lib/active_job/queue_adapters/sucker_punch_adapter.rb @@ -17,7 +17,7 @@ module ActiveJob include SuckerPunch::Job def perform(job, *args) - job.new.perform_with_hooks *args + job.new.execute *args end end end diff --git a/test/cases/callbacks_test.rb b/test/cases/callbacks_test.rb index 104519dcb7..01a9b9d26b 100644 --- a/test/cases/callbacks_test.rb +++ b/test/cases/callbacks_test.rb @@ -5,7 +5,7 @@ require 'active_support/core_ext/object/inclusion' class CallbacksTest < ActiveSupport::TestCase test 'perform callbacks' do - performed_callback_job = CallbackJob.new.tap { |j| j.perform_with_hooks } + performed_callback_job = CallbackJob.new.tap { |j| j.execute } assert "CallbackJob ran before_perform".in? performed_callback_job.history assert "CallbackJob ran after_perform".in? performed_callback_job.history assert "CallbackJob ran around_perform_start".in? performed_callback_job.history diff --git a/test/cases/rescue_test.rb b/test/cases/rescue_test.rb index ca4c69f91b..a91ed01f45 100644 --- a/test/cases/rescue_test.rb +++ b/test/cases/rescue_test.rb @@ -10,7 +10,7 @@ class RescueTest < ActiveSupport::TestCase test 'rescue perform exception with retry' do job = RescueJob.new - job.perform_with_hooks("david") + job.execute("david") assert_equal [ "rescued from StandardError", "performed beautifully" ], $BUFFER end end -- cgit v1.2.3