Class: Fiveruns::Dash::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/fiveruns/dash/reporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session, interval = 60) ⇒ Reporter

Returns a new instance of Reporter.



11
12
13
14
# File 'lib/fiveruns/dash/reporter.rb', line 11

def initialize(session, interval = 60)
  @session = session
  @interval = interval
end

Instance Attribute Details

#intervalObject

Returns the value of attribute interval.



9
10
11
# File 'lib/fiveruns/dash/reporter.rb', line 9

def interval
  @interval
end

#started_atObject (readonly)

Returns the value of attribute started_at.



10
11
12
# File 'lib/fiveruns/dash/reporter.rb', line 10

def started_at
  @started_at
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/fiveruns/dash/reporter.rb', line 21

def alive?
  @thread && @thread.alive? && started?
end

#background?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/fiveruns/dash/reporter.rb', line 47

def background?
  started? && @background
end

#foreground?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/fiveruns/dash/reporter.rb', line 43

def foreground?
  started? && !@background
end

#pingObject



61
62
63
64
# File 'lib/fiveruns/dash/reporter.rb', line 61

def ping
  payload = PingPayload.new(@session.info, @started_at)
  Update.new(payload).ping(*update_locations)
end

#revive!Object



16
17
18
19
# File 'lib/fiveruns/dash/reporter.rb', line 16

def revive!
  return if !started? || foreground?
  start if !@thread || !@thread.alive?
end

#secure!Object



70
71
72
# File 'lib/fiveruns/dash/reporter.rb', line 70

def secure!
  @update_locations = %w(https://dash-collector.fiveruns.com https://dash-collector02.fiveruns.com)
end

#send_trace(trace) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/fiveruns/dash/reporter.rb', line 51

def send_trace(trace)
  if trace.data
    payload = TracePayload.new(trace)
    Fiveruns::Dash.logger.debug "Sending trace: #{payload.to_fjson}"
    Thread.new { Update.new(payload).store(*update_locations) }
  else
    Fiveruns::Dash.logger.debug "No trace to send"      
  end
end

#start(run_in_background = true) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fiveruns/dash/reporter.rb', line 25

def start(run_in_background = true)
  restarted = @started_at ? true : false
  unless defined?(@started_at)
    @started_at = ::Fiveruns::Dash::START_TIME
  end
  setup_for run_in_background
  if @background
    @thread = Thread.new { run(restarted) }
  else
    # Will it be run in foreground?
    run(restarted)
  end
end

#started?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/fiveruns/dash/reporter.rb', line 39

def started?
  @started_at
end

#stopObject



66
67
68
# File 'lib/fiveruns/dash/reporter.rb', line 66

def stop
  @thread && @thread.alive? && @thread.raise(ShutdownSignal.new)
end