Skip to content

Commit

Permalink
Implement version v0.21 of the Spec - notify on round completion
Browse files Browse the repository at this point in the history
  • Loading branch information
julianghionoiu committed May 13, 2018
1 parent 746c52e commit c08a6a1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

ruby '2.2.2'
ruby '~> 2.2.2'

# Specify your gem's dependencies in tdl-client-ruby.gemspec
gemspec
2 changes: 1 addition & 1 deletion features/spec
7 changes: 6 additions & 1 deletion lib/tdl/runner/challenge_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,19 @@ def execute_user_action(user_input)
if user_input == 'deploy'
@runner.run
last_fetched_round = RoundManagement.get_last_fetched_round(@config.get_working_directory)
@recording_system.deploy_notify_event last_fetched_round
@recording_system.notify_event(last_fetched_round, RecordingEvent::ROUND_SOLUTION_DEPLOY)
end

execute_action user_input
end

def execute_action(user_input)
action_feedback = @challenge_server_client.send_action user_input
if action_feedback.include?('Round time for')
last_fetched_round = RoundManagement.get_last_fetched_round(@config.get_working_directory)
@recording_system.notify_event(last_fetched_round, RecordingEvent::ROUND_COMPLETED)
end

@audit_stream.write_line action_feedback
@challenge_server_client.get_round_description
end
Expand Down
28 changes: 16 additions & 12 deletions lib/tdl/runner/recording_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@

RECORDING_SYSTEM_ENDPOINT = 'http://localhost:41375'

module RecordingEvent
ROUND_START = 'new'
ROUND_SOLUTION_DEPLOY = 'deploy'
ROUND_COMPLETED = 'done'
end


class RecordingSystem

def initialize(recording_required)
@recording_required = recording_required
end
Expand All @@ -14,7 +21,7 @@ def is_recording_required
end

def is_recording_system_ok
return is_recording_required ? is_running : true
is_recording_required ? is_running : true
end

def is_running
Expand All @@ -29,28 +36,25 @@ def is_running
false
end

def deploy_notify_event(last_fetched_round)
notify_event(last_fetched_round, RunnerActions.deploy_to_production.short_name)
end

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

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

begin
response = Unirest.post "#{RECORDING_SYSTEM_ENDPOINT}/notify",
parameters:"#{last_fetched_round}/#{short_name}"
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
Expand Down
2 changes: 1 addition & 1 deletion lib/tdl/runner/round_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def save_description(listener, raw_description, audit_stream, working_directory)

newline_index = raw_description.index("\n")
round_id = raw_description[0..newline_index - 1]
listener.on_new_round(round_id, RunnerActions.get_new_round_description.short_name) if round_id != get_last_fetched_round(working_directory)
listener.on_new_round(round_id) if round_id != get_last_fetched_round(working_directory)

display_and_save_description(round_id, raw_description, audit_stream, working_directory)
end
Expand Down

0 comments on commit c08a6a1

Please sign in to comment.