module ActiveSupport::Notifications
def instrument(name, payload = {})
def instrument(name, payload = {}) if notifier.listening?(name) instrumenter.instrument(name, payload) { yield payload if block_given? } else yield payload if block_given? end end
def instrumenter
def instrumenter registry[notifier] ||= Instrumenter.new(notifier) end
def monotonic_subscribe(pattern = nil, callback = nil, &block)
duration is important. For example, computing elapsed time between
Daylights Savings). Use +monotonic_subscribe+ when accuracy of time
time. Monotonic time will not jump forward or backward (due to NTP or
+finish+ block arguments are in monotonic time instead of wall-clock
Performs the same functionality as #subscribe, but the +start+ and
def monotonic_subscribe(pattern = nil, callback = nil, &block) notifier.subscribe(pattern, callback, monotonic: true, &block) end
def publish(name, *args)
def publish(name, *args) notifier.publish(name, *args) end
def publish_event(event) # :nodoc:
def publish_event(event) # :nodoc: notifier.publish_event(event) end
def registry
def registry ActiveSupport::IsolatedExecutionState[:active_support_notifications_registry] ||= {} end
def subscribe(pattern = nil, callback = nil, &block)
#=> ArgumentError (pattern must be specified as a String, Regexp or empty)
ActiveSupport::Notifications.subscribe(:render) {|*args| ...}
Raises an error if invalid event name type is passed:
end
@event = event
ActiveSupport::Notifications.subscribe(/render/) do |event|
it will yield an event object to the block:
If the block passed to the method only takes one parameter,
end
payload # => Hash, the payload
id # => String, unique ID for the instrumenter that fired the event
finish # => Time, when the instrumented block ended execution
start # => Time, when the instrumented block started execution
name # => String, name of the event (such as 'render' from above)
ActiveSupport::Notifications.subscribe('render') do |name, start, finish, id, payload|
The +block+ will receive five parameters with information about the event:
end
@event = ActiveSupport::Notifications::Event.new(*args)
ActiveSupport::Notifications.subscribe(/render/) do |*args|
names, or by passing a Regexp to match all events that match a pattern.
You can subscribe to events by passing a String to match exact event
Subscribe to a given event name with the passed +block+.
def subscribe(pattern = nil, callback = nil, &block) notifier.subscribe(pattern, callback, monotonic: false, &block) end
def subscribed(callback, pattern = nil, monotonic: false, &block)
def subscribed(callback, pattern = nil, monotonic: false, &block) subscriber = notifier.subscribe(pattern, callback, monotonic: monotonic) yield ensure unsubscribe(subscriber) end
def unsubscribe(subscriber_or_name)
def unsubscribe(subscriber_or_name) notifier.unsubscribe(subscriber_or_name) end