Skip to content

Commit 17379ba

Browse files
rabbit:await_startup: progress reporting
Pair: @gerhard.
1 parent 44dabcf commit 17379ba

File tree

1 file changed

+35
-26
lines changed

1 file changed

+35
-26
lines changed

src/rabbit.erl

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
-behaviour(application).
2424

2525
-export([start/0, boot/0, stop/0,
26-
stop_and_halt/0, await_startup/0, await_startup/1, await_startup/2,
26+
stop_and_halt/0, await_startup/0, await_startup/1, await_startup/3,
2727
status/0, is_running/0, alarms/0,
2828
is_running/1, environment/0, rotate_logs/0,
2929
start_fhc/0]).
@@ -699,35 +699,36 @@ is_booting(Node) ->
699699

700700

701701
-spec await_startup() -> 'ok' | {'error', 'timeout'}.
702-
703702
await_startup() ->
704-
await_startup(node()).
703+
await_startup(node(), false).
705704

706705
-spec await_startup(node() | non_neg_integer()) -> 'ok' | {'error', 'timeout'}.
707-
708-
await_startup(Timeout) when is_integer(Timeout) ->
709-
await_startup(node(), Timeout);
710706
await_startup(Node) when is_atom(Node) ->
707+
await_startup(Node, false);
708+
await_startup(Timeout) when is_integer(Timeout) ->
709+
await_startup(node(), false, Timeout).
710+
711+
-spec await_startup(node(), boolean()) -> 'ok' | {'error', 'timeout'}.
712+
await_startup(Node, PrintProgressReports) ->
711713
case is_booting(Node) of
712-
true -> wait_for_boot_to_finish(Node);
714+
true -> wait_for_boot_to_finish(Node, PrintProgressReports);
713715
false ->
714716
case is_running(Node) of
715-
true -> ok;
717+
true -> ok;
716718
false -> wait_for_boot_to_start(Node),
717-
wait_for_boot_to_finish(Node)
719+
wait_for_boot_to_finish(Node, PrintProgressReports)
718720
end
719721
end.
720722

721-
-spec await_startup(node(), non_neg_integer()) -> 'ok' | {'error', 'timeout'}.
722-
723-
await_startup(Node, Timeout) ->
723+
-spec await_startup(node(), boolean(), non_neg_integer()) -> 'ok' | {'error', 'timeout'}.
724+
await_startup(Node, PrintProgressReports, Timeout) ->
724725
case is_booting(Node) of
725-
true -> wait_for_boot_to_finish(Node, Timeout);
726+
true -> wait_for_boot_to_finish(Node, PrintProgressReports, Timeout);
726727
false ->
727728
case is_running(Node) of
728729
true -> ok;
729730
false -> wait_for_boot_to_start(Node, Timeout),
730-
wait_for_boot_to_finish(Node, Timeout)
731+
wait_for_boot_to_finish(Node, PrintProgressReports, Timeout)
731732
end
732733
end.
733734

@@ -752,15 +753,18 @@ do_wait_for_boot_to_start(Node, IterationsLeft) ->
752753
end.
753754

754755
wait_for_boot_to_finish(Node) ->
755-
wait_for_boot_to_finish(Node, ?BOOT_FINISH_TIMEOUT).
756+
wait_for_boot_to_finish(Node, false, ?BOOT_FINISH_TIMEOUT).
757+
758+
wait_for_boot_to_finish(Node, PrintProgressReports) ->
759+
wait_for_boot_to_finish(Node, PrintProgressReports, ?BOOT_FINISH_TIMEOUT).
756760

757-
wait_for_boot_to_finish(Node, Timeout) ->
761+
wait_for_boot_to_finish(Node, PrintProgressReports, Timeout) ->
758762
Iterations = Timeout div ?BOOT_STATUS_CHECK_INTERVAL,
759-
do_wait_for_boot_to_finish(Node, Iterations).
763+
do_wait_for_boot_to_finish(Node, PrintProgressReports, Iterations).
760764

761-
do_wait_for_boot_to_finish(_Node, IterationsLeft) when IterationsLeft =< 0 ->
765+
do_wait_for_boot_to_finish(_Node, _PrintProgressReports, IterationsLeft) when IterationsLeft =< 0 ->
762766
{error, timeout};
763-
do_wait_for_boot_to_finish(Node, IterationsLeft) ->
767+
do_wait_for_boot_to_finish(Node, PrintProgressReports, IterationsLeft) ->
764768
case is_booting(Node) of
765769
false ->
766770
%% We don't want badrpc error to be interpreted as false,
@@ -773,16 +777,21 @@ do_wait_for_boot_to_finish(Node, IterationsLeft) ->
773777
{badrpc, _} = Err ->
774778
Err;
775779
true ->
776-
case IterationsLeft rem 100 of
777-
%% This will be printed on the CLI command end to illustrate some
778-
%% progress.
779-
0 -> io:format("Still booting, will check again in 10 seconds...~n");
780-
_ -> ok
781-
end,
780+
maybe_print_boot_progress(PrintProgressReports, IterationsLeft),
782781
timer:sleep(?BOOT_STATUS_CHECK_INTERVAL),
783-
do_wait_for_boot_to_finish(Node, IterationsLeft - 1)
782+
do_wait_for_boot_to_finish(Node, PrintProgressReports, IterationsLeft - 1)
784783
end.
785784

785+
maybe_print_boot_progress(false = _PrintProgressReports, _IterationsLeft) ->
786+
ok;
787+
maybe_print_boot_progress(true, IterationsLeft) ->
788+
case IterationsLeft rem 100 of
789+
%% This will be printed on the CLI command end to illustrate some
790+
%% progress.
791+
0 -> io:format("Still booting, will check again in 10 seconds...~n");
792+
_ -> ok
793+
end.
794+
786795
status() ->
787796
S1 = [{pid, list_to_integer(os:getpid())},
788797
%% The timeout value used is twice that of gen_server:call/2.

0 commit comments

Comments
 (0)