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

Admin client: fix ref-counting on progress display #138

Merged
merged 1 commit into from
Jul 14, 2021
Merged
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
15 changes: 10 additions & 5 deletions bin/admin.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ let show () cap_path pool =
Cluster_api.Pool_admin.show pool >|= fun status ->
print_endline (String.trim status)

let progress label = Cluster_api.Progress.local (Fmt.pr "%s: %s@." label)
let with_progress label =
Capability.with_ref (Cluster_api.Progress.local (Fmt.pr "%s: %s@." label))

let drain pool workers =
Fmt.pr "Waiting for jobs to finish...@.";
let jobs = workers |> List.map (fun w ->
Cluster_api.Pool_admin.drain ~progress:(progress w) pool w
with_progress w @@ fun progress ->
Cluster_api.Pool_admin.drain ~progress pool w
) in
Lwt.join jobs

Expand Down Expand Up @@ -109,7 +111,8 @@ let update () cap_path pool worker =
match worker with
| Some worker ->
begin
Cluster_api.Pool_admin.update ~progress:(progress worker) pool worker >|= function
with_progress worker @@ fun progress ->
Cluster_api.Pool_admin.update ~progress pool worker >|= function
| Ok () -> Fmt.pr "Restarted@."
| Error (`Capnp ex) ->
Fmt.pr "%a@." Capnp_rpc.Error.pp ex;
Expand All @@ -125,7 +128,8 @@ let update () cap_path pool worker =
exit 1
| w :: ws ->
Fmt.pr "Testing update on first worker in pool: %S@." w.name;
Cluster_api.Pool_admin.update ~progress:(progress w.name) pool w.name >>= function
with_progress w.name (fun progress -> Cluster_api.Pool_admin.update ~progress pool w.name)
>>= function
| Error (`Capnp ex) ->
Fmt.pr "%a@." Capnp_rpc.Error.pp ex;
exit 1
Expand All @@ -134,7 +138,8 @@ let update () cap_path pool worker =
Fmt.(list ~sep:sp pp_worker_name) ws;
ws
|> List.map (fun (w:Cluster_api.Pool_admin.worker_info) ->
Cluster_api.Pool_admin.update ~progress:(progress w.name) pool w.name >|= function
with_progress w.name @@ fun progress ->
Cluster_api.Pool_admin.update ~progress pool w.name >|= function
| Ok () -> Fmt.pr "%S restarted OK.@." w.name
| Error (`Capnp ex) ->
Fmt.pr "%S: %a@." w.name Capnp_rpc.Error.pp ex;
Expand Down