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

feat: PPT-1701 refactored recompile/reload logic #395

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Changes from 1 commit
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
36 changes: 18 additions & 18 deletions src/placeos-rest-api/controllers/drivers.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require "wait_group"
require "./application"

module PlaceOS::Api
Expand Down Expand Up @@ -132,26 +131,27 @@ module PlaceOS::Api

def self.driver_reload(driver : ::PlaceOS::Model::Driver, request_id : String) : Tuple(Int32, String)
cores = RemoteDriver.default_discovery.node_hash
wg = WaitGroup.new
channel = Channel(Tuple(Int32, String)).new(cores.size)
cores.each do |core_id, uri|
wg.spawn do
client = PlaceOS::Core::Client.new(uri: uri, request_id: request_id)
resp = client.driver_reload(driver.id.as(String))
channel.send(resp)
rescue error
Log.error(exception: error) { {
message: "failure to request a driver reload on core node",
core_uri: uri.to_s,
core_id: core_id,
driver: driver.id.as(String),
request_id: request_id,
} }
channel.send({500, "failed to request a driver reload on core #{uri}: error: #{error.message}"})
end
cores.each do |cid, core_uri|
->(core_id : String, uri : URI) do
spawn do
client = PlaceOS::Core::Client.new(uri: uri, request_id: request_id)
resp = client.driver_reload(driver.id.as(String))
channel.send(resp)
rescue error
Log.error(exception: error) { {
message: "failure to request a driver reload on core node",
core_uri: uri.to_s,
core_id: core_id,
driver: driver.id.as(String),
request_id: request_id,
} }
channel.send({500, "failed to request a driver reload on core #{uri}: error: #{error.message}"})
end
end.call(cid, core_uri)
end

wg.wait
Fiber.yield

naqvis marked this conversation as resolved.
Show resolved Hide resolved
resps = cores.map do |_, _|
channel.receive
Expand Down
Loading