Class: RecordingSystem
- Inherits:
-
Object
- Object
- RecordingSystem
- Defined in:
- lib/tdl/runner/recording_system.rb
Instance Method Summary collapse
- #_send_post(endpoint, body) ⇒ Object
-
#initialize(recording_required) ⇒ RecordingSystem
constructor
A new instance of RecordingSystem.
- #is_recording_required ⇒ Object
- #is_recording_system_ok ⇒ Object
- #is_running ⇒ Object
- #notify_event(round_id, event_name) ⇒ Object
- #on_new_round(round_id) ⇒ Object
- #tell_to_stop ⇒ Object
Constructor Details
#initialize(recording_required) ⇒ RecordingSystem
Returns a new instance of RecordingSystem.
16 17 18 |
# File 'lib/tdl/runner/recording_system.rb', line 16 def initialize(recording_required) @recording_required = recording_required end |
Instance Method Details
#_send_post(endpoint, body) ⇒ Object
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 55 def _send_post(endpoint, body) unless @recording_required return end begin response = Net::HTTP.post(URI("#{RECORDING_SYSTEM_ENDPOINT}#{endpoint}"), body) unless response.is_a?(Net::HTTPSuccess) 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.}" end end |
#is_recording_required ⇒ Object
20 21 22 |
# File 'lib/tdl/runner/recording_system.rb', line 20 def is_recording_required @recording_required end |
#is_recording_system_ok ⇒ Object
24 25 26 |
# File 'lib/tdl/runner/recording_system.rb', line 24 def is_recording_system_ok is_recording_required ? is_running : true end |
#is_running ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/tdl/runner/recording_system.rb', line 28 def is_running begin response = Net::HTTP.get_response(URI("#{RECORDING_SYSTEM_ENDPOINT}/status")) if response.is_a?(Net::HTTPSuccess) and response.body.start_with?('OK') return true end rescue StandardError => e puts "Could not reach recording system: #{e.}" end false end |
#notify_event(round_id, event_name) ⇒ Object
45 46 47 48 |
# File 'lib/tdl/runner/recording_system.rb', line 45 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
41 42 43 |
# File 'lib/tdl/runner/recording_system.rb', line 41 def on_new_round(round_id) notify_event(round_id, RecordingEvent::ROUND_START) end |
#tell_to_stop ⇒ Object
50 51 52 53 |
# File 'lib/tdl/runner/recording_system.rb', line 50 def tell_to_stop puts "Stopping recording system" _send_post("/stop", "") end |