Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Server::Master #350

Merged
merged 2 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions lib/steep/drivers/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ def run

Steep.logger.info { "Shutting down..." }

client_writer.write({ method: :shutdown, id: request_id() })
client_writer.write({ method: :exit })
client_writer.io.close()

shutdown_exit(reader: client_reader, writer: client_writer)
main_thread.join()

stdout.puts
Expand Down
4 changes: 1 addition & 3 deletions lib/steep/drivers/stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ def run
stats_response = wait_for_response_id(reader: client_reader, id: stats_id)
stats_result = stats_response[:result]

shutdown_id = request_id()
client_writer.write({ method: :shutdown, id: shutdown_id })
client_writer.write({ method: "exit" })
shutdown_exit(reader: client_reader, writer: client_writer)
main_thread.join()

stdout.puts(
Expand Down
10 changes: 9 additions & 1 deletion lib/steep/drivers/utils/driver_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def type_check(project)
end

def request_id
(Time.now.to_f * 1000).to_i
SecureRandom.alphanumeric(10)
end

def wait_for_response_id(reader:, id:, unknown_responses: :ignore)
Expand All @@ -31,6 +31,14 @@ def wait_for_response_id(reader:, id:, unknown_responses: :ignore)
end
end

def shutdown_exit(writer:, reader:)
request_id().tap do |id|
writer.write({ method: :shutdown, id: id })
wait_for_response_id(reader: reader, id: id)
end
writer.write({ method: :exit })
end

def wait_for_message(reader:, unknown_messages: :ignore, &block)
reader.read do |message|
if yield(message)
Expand Down
5 changes: 1 addition & 4 deletions lib/steep/drivers/watch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,8 @@ def run()
end
end
rescue Interrupt
shutdown_id = request_id()
stdout.puts "Shutting down workers..."
client_writer.write({ method: :shutdown, id: shutdown_id })
client_writer.write({ method: :exit })
client_writer.io.close()
shutdown_exit(reader: client_reader, writer: client_writer)
end

listener.stop
Expand Down
Loading