aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorEileen M. Uchitelle <eileencodes@users.noreply.github.com>2019-03-22 14:02:38 -0400
committerGitHub <noreply@github.com>2019-03-22 14:02:38 -0400
commit75f19b5deb02410ea41a934d3bc822cec106fa6c (patch)
tree25de7f6604622c82d66d5016a510a96fc769ef2a /activesupport/lib
parentf40860800c231ecd1daef6cf6b5a8a8eda76478d (diff)
parent7237c7be74b09cd951ff000afb4087313e5c0025 (diff)
downloadrails-75f19b5deb02410ea41a934d3bc822cec106fa6c.tar.gz
rails-75f19b5deb02410ea41a934d3bc822cec106fa6c.tar.bz2
rails-75f19b5deb02410ea41a934d3bc822cec106fa6c.zip
Merge pull request #35705 from alimi/instrumenter-block-optional
Update AS::Notifications::Instrumenter#instrument
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/notifications/instrumenter.rb9
1 files changed, 5 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb
index 00a57c38c9..a03e7e483e 100644
--- a/activesupport/lib/active_support/notifications/instrumenter.rb
+++ b/activesupport/lib/active_support/notifications/instrumenter.rb
@@ -13,14 +13,15 @@ module ActiveSupport
@notifier = notifier
end
- # Instrument the given block by measuring the time taken to execute it
- # and publish it. Notice that events get sent even if an error occurs
- # in the passed-in block.
+ # Given a block, instrument it by measuring the time taken to execute
+ # and publish it. Without a block, simply send a message via the
+ # notifier. Notice that events get sent even if an error occurs in the
+ # passed-in block.
def instrument(name, payload = {})
# some of the listeners might have state
listeners_state = start name, payload
begin
- yield payload
+ yield payload if block_given?
rescue Exception => e
payload[:exception] = [e.class.name, e.message]
payload[:exception_object] = e