Sha256: 15498b5ab0c7360ba772488bb8efbcf32b23c508574605ca9609fe9188c10f0b
Contents?: true
Size: 1.31 KB
Versions: 7
Compression:
Stored size: 1.31 KB
Contents
# encoding: utf-8 # This file is distributed under New Relic's license terms. # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. module NewRelic::Agent # Basic mechanism for the agent instance to provide agent-wide eventing. # It is intended to keep different pieces of the app decoupled from each other. # # While an EventListener could be used elsewhere, it's strongly expected # your eventing needs should be met by the agent's instance. class EventListener attr_accessor :runaway_threshold def initialize @events = {} @runaway_threshold = 100 end def subscribe(event, &handler) @events[event] ||= [] @events[event] << handler check_for_runaway_subscriptions(event) end def check_for_runaway_subscriptions(event) count = @events[event].size NewRelic::Agent.logger.debug("Run-away event subscription on #{event}? Subscribed #{count}") if count > @runaway_threshold end def clear @events.clear end def notify(event, *args) return unless @events.has_key?(event) @events[event].each do |handler| begin handler.call(*args) rescue => err NewRelic::Agent.logger.debug("Failure during notify for #{event}", err) end end end end end
Version data entries
7 entries across 7 versions & 1 rubygems