aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/notifications.rb2
-rw-r--r--activesupport/lib/active_support/notifications/instrumenter.rb9
2 files changed, 10 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb
index 3e96decb8c..a1383bb478 100644
--- a/activesupport/lib/active_support/notifications.rb
+++ b/activesupport/lib/active_support/notifications.rb
@@ -45,7 +45,7 @@ module ActiveSupport
class << self
attr_writer :notifier
delegate :publish, :subscribe, :to => :notifier
- delegate :instrument, :to => :instrumenter
+ delegate :instrument, :instrument!, :to => :instrumenter
def notifier
@notifier ||= Notifier.new
diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb
index f3d877efe7..7c5b118ee3 100644
--- a/activesupport/lib/active_support/notifications/instrumenter.rb
+++ b/activesupport/lib/active_support/notifications/instrumenter.rb
@@ -20,6 +20,15 @@ module ActiveSupport
result
end
+ # The same as instrument, but sends the notification even if the yielded
+ # block raises an error.
+ def instrument!(name, payload={})
+ time = Time.now
+ yield(payload) if block_given?
+ ensure
+ @notifier.publish(name, time, Time.now, @id, payload)
+ end
+
private
def unique_id
SecureRandom.hex(10)