Skip to content

Commit 7b36b7f

Browse files
author
Alexey Lebedeff
committed
Default timeouts: fix global/add per-command
- Global timeout `?RPC_TIMEOUT` was not used, because default value of infinity was always introduced via `?TIMEOUT_DEF`. Now `infinity` is used for commands without timeout support, and `?RPC_TIMEOUT` otherwise. - `?COMMANDS_WITH_TIMEOUT` now can contain per-command default values for timeout, using tuple `{Command, DefaultTimeoutInMilliSeconds}` instead of just `Command`.
1 parent 3448f97 commit 7b36b7f

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

include/rabbit_cli.hrl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
-define(NODE_DEF(Node), {?NODE_OPT, {option, Node}}).
3535
-define(QUIET_DEF, {?QUIET_OPT, flag}).
3636
-define(VHOST_DEF, {?VHOST_OPT, {option, "/"}}).
37-
-define(TIMEOUT_DEF, {?TIMEOUT_OPT, {option, "infinity"}}).
37+
-define(TIMEOUT_DEF, {?TIMEOUT_OPT, {option, use_default}}).
3838

3939
-define(VERBOSE_DEF, {?VERBOSE_OPT, flag}).
4040
-define(MINIMAL_DEF, {?MINIMAL_OPT, flag}).

src/rabbit_control_main.erl

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
forget_cluster_node, rename_cluster_node, cluster_status, status,
117117
environment, eval, force_boot, help, node_health_check, hipe_compile]).
118118

119+
%% [Command | {Command, DefaultTimeoutInMilliSeconds}]
119120
-define(COMMANDS_WITH_TIMEOUT,
120121
[list_user_permissions, list_policies, list_queues, list_exchanges,
121122
list_bindings, list_connections, list_channels, list_consumers,
@@ -152,7 +153,7 @@ start() ->
152153
end
153154
end,
154155
try
155-
T = case get_timeout(Opts) of
156+
T = case get_timeout(Command, Opts) of
156157
{ok, Timeout} ->
157158
Timeout;
158159
{error, _} ->
@@ -187,8 +188,23 @@ print_report0(Node, {Module, InfoFun, KeysFun}, VHostArg) ->
187188
end,
188189
io:nl().
189190

190-
get_timeout(Opts) ->
191-
parse_timeout(proplists:get_value(?TIMEOUT_OPT, Opts, ?RPC_TIMEOUT)).
191+
get_timeout(Command, Opts) ->
192+
Default = case proplists:lookup(Command, ?COMMANDS_WITH_TIMEOUT) of
193+
none ->
194+
infinity;
195+
{Command, true} ->
196+
?RPC_TIMEOUT;
197+
{Command, D} ->
198+
D
199+
end,
200+
Result = case proplists:get_value(?TIMEOUT_OPT, Opts, Default) of
201+
use_default ->
202+
parse_timeout(Default);
203+
Value ->
204+
parse_timeout(Value)
205+
end,
206+
Result.
207+
192208

193209
parse_number(N) when is_list(N) ->
194210
try list_to_integer(N) of
@@ -234,11 +250,11 @@ do_action(Command, Node, Args, Opts, Inform, Timeout) ->
234250
false ->
235251
case ensure_app_running(Node) of
236252
ok ->
237-
case lists:member(Command, ?COMMANDS_WITH_TIMEOUT) of
238-
true ->
253+
case proplists:lookup(Command, ?COMMANDS_WITH_TIMEOUT) of
254+
{Command, _} ->
239255
announce_timeout(Timeout, Inform),
240256
action(Command, Node, Args, Opts, Inform, Timeout);
241-
false ->
257+
none ->
242258
action(Command, Node, Args, Opts, Inform)
243259
end;
244260
E -> E

0 commit comments

Comments
 (0)