Class: RecordingSystem

Inherits:
Object
  • Object
show all
Defined in:
lib/tdl/runner/recording_system.rb

Instance Method Summary collapse

Constructor Details

#initialize(recording_required) ⇒ RecordingSystem

Returns a new instance of RecordingSystem.



15
16
17
# File 'lib/tdl/runner/recording_system.rb', line 15

def initialize(recording_required)
    @recording_required = recording_required
end

Instance Method Details

#_send_post(endpoint, body) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/tdl/runner/recording_system.rb', line 54

def _send_post(endpoint, body)
  unless @recording_required
    return
  end

  begin
    response = Unirest.post "#{RECORDING_SYSTEM_ENDPOINT}#{endpoint}",
                            parameters: body

    unless response.code == 200
      puts "Recording system returned code: #{response.code}"
      return
    end

    unless response.body.start_with?('ACK')
      puts "Recording system returned body: #{response.body}"
    end
  rescue StandardError => e
    puts "Could not reach recording system: #{e.message}"
  end
end

#is_recording_requiredObject



19
20
21
# File 'lib/tdl/runner/recording_system.rb', line 19

def is_recording_required
    @recording_required
end

#is_recording_system_okObject



23
24
25
# File 'lib/tdl/runner/recording_system.rb', line 23

def is_recording_system_ok
  is_recording_required ? is_running : true
end

#is_runningObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/tdl/runner/recording_system.rb', line 27

def is_running
    begin
        response = Unirest.get "#{RECORDING_SYSTEM_ENDPOINT}/status"
        if response.code == 200 and response.body.start_with?('OK')
            return true
        end
    rescue StandardError => e
        puts "Could not reach recording system: #{e.message}"
    end
    false
end

#notify_event(round_id, event_name) ⇒ Object



44
45
46
47
# File 'lib/tdl/runner/recording_system.rb', line 44

def notify_event(round_id, event_name)
  puts "Notify round #{round_id}, event #{event_name}"
  _send_post("/notify", "#{round_id}/#{event_name}")
end

#on_new_round(round_id) ⇒ Object



40
41
42
# File 'lib/tdl/runner/recording_system.rb', line 40

def on_new_round(round_id)
    notify_event(round_id, RecordingEvent::ROUND_START)
end

#tell_to_stopObject



49
50
51
52
# File 'lib/tdl/runner/recording_system.rb', line 49

def tell_to_stop
  puts "Stopping recording system"
  _send_post("/stop", "")
end