diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2014-05-22 17:08:23 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2014-05-22 17:08:23 +0200 |
commit | b1793ac0043e815356b2a7a5f35bc9cae91c2385 (patch) | |
tree | 419b23c659e6a850e950dd7d88e7f464f0435729 | |
parent | 50abad3fe7450f87606d36a196604ff9ad79d3bf (diff) | |
download | rails-b1793ac0043e815356b2a7a5f35bc9cae91c2385.tar.gz rails-b1793ac0043e815356b2a7a5f35bc9cae91c2385.tar.bz2 rails-b1793ac0043e815356b2a7a5f35bc9cae91c2385.zip |
Hide the instrumentation mechanics a little better
-rw-r--r-- | lib/active_job/enqueuing.rb | 12 | ||||
-rw-r--r-- | lib/active_job/performing.rb | 7 |
2 files changed, 14 insertions, 5 deletions
diff --git a/lib/active_job/enqueuing.rb b/lib/active_job/enqueuing.rb index 652de5521b..e8f3272782 100644 --- a/lib/active_job/enqueuing.rb +++ b/lib/active_job/enqueuing.rb @@ -11,7 +11,7 @@ module ActiveJob # ActiveJob release. def enqueue(*args) serialized_args = Parameters.serialize(args) - ActiveSupport::Notifications.instrument "enqueue.active_job", adapter: queue_adapter, job: self, args: serialized_args + instrument_enqueuing :enqueue, args: serialized_args queue_adapter.enqueue self, *serialized_args end @@ -30,10 +30,14 @@ module ActiveJob # # Returns truthy if a job was scheduled. def enqueue_at(timestamp, *args) - timestamp = timestamp.to_f serialized_args = Parameters.serialize(args) - ActiveSupport::Notifications.instrument "enqueue_at.active_job", adapter: queue_adapter, job: self, args: serialized_args, timestamp: timestamp - queue_adapter.enqueue_at self, timestamp, *serialized_args + instrument_enqueuing :enqueue_at, args: serialized_args, timestamp: timestamp + queue_adapter.enqueue_at self, timestamp.to_f, *serialized_args end + + private + def instrument_enqueuing(method_name, options = {}) + ActiveSupport::Notifications.instrument "#{method_name}.active_job", options.merge(adapter: queue_adapter, job: self) + end end end diff --git a/lib/active_job/performing.rb b/lib/active_job/performing.rb index 6c304a4bed..eca311578d 100644 --- a/lib/active_job/performing.rb +++ b/lib/active_job/performing.rb @@ -3,12 +3,17 @@ require 'active_job/parameters' module ActiveJob module Performing def perform_with_deserialization(*serialized_args) - ActiveSupport::Notifications.instrument "perform.active_job", adapter: self.class.queue_adapter, job: self.class, args: serialized_args + instrument_performing serialized_args perform *Parameters.deserialize(serialized_args) end def perform(*) raise NotImplementedError end + + private + def instrument_performing(args) + ActiveSupport::Notifications.instrument "perform.active_job", adapter: self.class.queue_adapter, job: self.class, args: args + end end end |