Skip to content

Commit

Permalink
Merge pull request #138 from talex5/ref-progress
Browse files Browse the repository at this point in the history
Admin client: fix ref-counting on progress display
  • Loading branch information
talex5 committed Jul 14, 2021
2 parents f876c07 + 9db5ed5 commit b9854a3
Showing 1 changed file with 10 additions and 5 deletions.
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

0 comments on commit b9854a3

Please sign in to comment.