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

#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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/tdl/runner/recording_system.rb', line 44

def notify_event(round_id, event_name)
    if not @recording_required
      return
    end

    begin
      response = Unirest.post "#{RECORDING_SYSTEM_ENDPOINT}/notify",
                              parameters:"#{round_id}/#{event_name}"

      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

#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