Class: AppPerfRpm::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/app_perf_rpm/dispatcher.rb

Instance Method Summary collapse

Constructor Details

#initializeDispatcher

Returns a new instance of Dispatcher.



5
6
7
8
9
# File 'lib/app_perf_rpm/dispatcher.rb', line 5

def initialize
  @start_time = Time.now
  @queue = Queue.new
  @aggregator = Aggregator.new
end

Instance Method Details

#add_event(event) ⇒ Object



11
12
13
# File 'lib/app_perf_rpm/dispatcher.rb', line 11

def add_event(event)
  @queue << event
end

#configurationObject



15
16
17
# File 'lib/app_perf_rpm/dispatcher.rb', line 15

def configuration
  ::AppPerfRpm.configuration
end

#dispatchObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/app_perf_rpm/dispatcher.rb', line 29

def dispatch
  begin
    spans = drain(@queue)
    metrics = []#@aggregator.aggregate(spans)

    dispatch_events(spans.map(&:to_a) + metrics)
  rescue => ex
    ::AppPerfRpm.logger.error "#{ex.inspect}"
    ::AppPerfRpm.logger.error "#{ex.backtrace.inspect}"
  ensure
    reset
  end
end

#ready?Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/app_perf_rpm/dispatcher.rb', line 19

def ready?
  Time.now > @start_time + configuration.dispatch_interval.to_f &&
  @queue.size.to_i > 0
end

#resetObject



24
25
26
27
# File 'lib/app_perf_rpm/dispatcher.rb', line 24

def reset
  @queue.clear
  @start_time = Time.now
end