class RecordingSystem

Public Class Methods

new(recording_required) click to toggle source
# File lib/tdl/runner/recording_system.rb, line 15
def initialize(recording_required)
    @recording_required = recording_required
end

Public Instance Methods

_send_post(endpoint, body) click to toggle source
# 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_required() click to toggle source
# File lib/tdl/runner/recording_system.rb, line 19
def is_recording_required
    @recording_required
end
is_recording_system_ok() click to toggle source
# File lib/tdl/runner/recording_system.rb, line 23
def is_recording_system_ok
  is_recording_required ? is_running : true
end
is_running() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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_stop() click to toggle source
# File lib/tdl/runner/recording_system.rb, line 49
def tell_to_stop
  puts "Stopping recording system"
  _send_post("/stop", "")
end