Class: AppPerfAgent::Dispatcher
- Inherits:
-
Object
- Object
- AppPerfAgent::Dispatcher
- Defined in:
- lib/app_perf_agent/dispatcher.rb
Instance Method Summary collapse
- #add_event(event) ⇒ Object
- #dispatch ⇒ Object
- #dispatch_interval ⇒ Object
-
#initialize ⇒ Dispatcher
constructor
A new instance of Dispatcher.
- #queue_empty? ⇒ Boolean
- #ready? ⇒ Boolean
- #reset ⇒ Object
Constructor Details
#initialize ⇒ Dispatcher
Returns a new instance of Dispatcher.
7 8 9 10 |
# File 'lib/app_perf_agent/dispatcher.rb', line 7 def initialize @start_time = Time.now @queue = Queue.new end |
Instance Method Details
#add_event(event) ⇒ Object
12 13 14 |
# File 'lib/app_perf_agent/dispatcher.rb', line 12 def add_event(event) @queue << event end |
#dispatch ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/app_perf_agent/dispatcher.rb', line 33 def dispatch begin events = drain(@queue) dispatch_events(events.dup) rescue => ex ::AppPerfAgent.logger.error "#{ex.inspect}" ::AppPerfAgent.logger.error "#{ex.backtrace.inspect}" ensure reset end end |
#dispatch_interval ⇒ Object
20 21 22 |
# File 'lib/app_perf_agent/dispatcher.rb', line 20 def dispatch_interval 30 end |
#queue_empty? ⇒ Boolean
16 17 18 |
# File 'lib/app_perf_agent/dispatcher.rb', line 16 def queue_empty? @queue.size.to_i == 0 end |
#ready? ⇒ Boolean
24 25 26 |
# File 'lib/app_perf_agent/dispatcher.rb', line 24 def ready? Time.now > @start_time + dispatch_interval.to_f && !queue_empty? end |
#reset ⇒ Object
28 29 30 31 |
# File 'lib/app_perf_agent/dispatcher.rb', line 28 def reset @queue.clear @start_time = Time.now end |