Skip to content

Commit dbff137

Browse files
Address review feedback #14425
1 parent 3043dc6 commit dbff137

File tree

4 files changed

+35
-40
lines changed

4 files changed

+35
-40
lines changed

deps/rabbitmq_shovel/src/rabbit_shovel_dyn_worker_sup_sup.erl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ start_link() ->
2626
{ok, Pid0} -> Pid0;
2727
{error, {already_started, Pid0}} -> Pid0
2828
end,
29-
IsStandard = rabbit_shovel_operating_mode:is_standard(),
30-
Shovels = case IsStandard of
31-
false ->
29+
OpMode = rabbit_shovel_operating_mode:operating_mode(),
30+
Shovels = case OpMode of
31+
standard ->
32+
rabbit_runtime_parameters:list_component(<<"shovel">>);
33+
_Other ->
3234
%% when operating in a non-standard mode, do not start any shovels
33-
[];
34-
true ->
35-
rabbit_runtime_parameters:list_component(<<"shovel">>)
35+
[]
3636
end,
3737
[start_child({pget(vhost, Shovel), pget(name, Shovel)},
3838
pget(value, Shovel)) || Shovel <- Shovels],

deps/rabbitmq_shovel/src/rabbit_shovel_operating_mode.erl

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
-include("rabbit_shovel.hrl").
1111

1212
-export([
13-
operating_mode/0,
14-
is_standard/0,
15-
is_alternative/0
13+
operating_mode/0
1614
]).
1715

1816
-type operating_mode() :: 'standard' | atom().
@@ -24,11 +22,3 @@
2422
-spec operating_mode() -> operating_mode().
2523
operating_mode() ->
2624
application:get_env(?SHOVEL_APP, operating_mode, standard).
27-
28-
-spec is_standard() -> boolean().
29-
is_standard() ->
30-
operating_mode() =:= standard.
31-
32-
-spec is_alternative() -> boolean().
33-
is_alternative() ->
34-
operating_mode() =/= standard.

deps/rabbitmq_shovel/src/rabbit_shovel_parameters.erl

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,21 @@
3939
{enables, recovery}]}).
4040

4141
register() ->
42-
case rabbit_shovel_operating_mode:is_standard() of
43-
true ->
42+
OpMode = rabbit_shovel_operating_mode:operating_mode(),
43+
case OpMode of
44+
standard ->
4445
rabbit_registry:register(runtime_parameter, <<"shovel">>, ?MODULE);
45-
false ->
46-
?LOG_DEBUG("Shovel: skipping runtime parameter registration, operating mode: ~ts", [rabbit_shovel_operating_mode:operating_mode()])
46+
_Other ->
47+
?LOG_DEBUG("Shovel: skipping runtime parameter registration, operating mode: ~ts", [OpMode])
4748
end.
4849

4950
unregister() ->
50-
case rabbit_shovel_operating_mode:is_standard() of
51-
true ->
51+
OpMode = rabbit_shovel_operating_mode:operating_mode(),
52+
case OpMode of
53+
standard ->
5254
rabbit_registry:unregister(runtime_parameter, <<"shovel">>);
53-
false ->
54-
?LOG_DEBUG("Shovel: skipping runtime parameter deregistration, operating mode: ~ts", [rabbit_shovel_operating_mode:operating_mode()])
55+
_Other ->
56+
?LOG_DEBUG("Shovel: skipping runtime parameter deregistration, operating mode: ~ts", [OpMode])
5557
end.
5658

5759
validate(_VHost, <<"shovel">>, Name, Def0, User) ->
@@ -75,19 +77,21 @@ pget2(K1, K2, Defs) -> case {pget(K1, Defs), pget(K2, Defs)} of
7577
end.
7678

7779
notify(VHost, <<"shovel">>, Name, Definition, _Username) ->
78-
case rabbit_shovel_operating_mode:is_standard() of
79-
true ->
80+
OpMode = rabbit_shovel_operating_mode:operating_mode(),
81+
case OpMode of
82+
standard ->
8083
rabbit_shovel_dyn_worker_sup_sup:adjust({VHost, Name}, Definition);
81-
false ->
82-
?LOG_DEBUG("Shovel: ignoring a runtime parameter update, operating mode: ~ts", [rabbit_shovel_operating_mode:operating_mode()])
84+
_Other ->
85+
?LOG_DEBUG("Shovel: ignoring a runtime parameter update, operating mode: ~ts", [OpMode])
8386
end.
8487

8588
notify_clear(VHost, <<"shovel">>, Name, _Username) ->
86-
case rabbit_shovel_operating_mode:is_standard() of
87-
true ->
89+
OpMode = rabbit_shovel_operating_mode:operating_mode(),
90+
case OpMode of
91+
standard ->
8892
rabbit_shovel_dyn_worker_sup_sup:stop_child({VHost, Name});
89-
false ->
90-
?LOG_DEBUG("Shovel: ignoring a cleared runtime parameter, operating mode: ~ts", [rabbit_shovel_operating_mode:operating_mode()])
93+
_Other ->
94+
?LOG_DEBUG("Shovel: ignoring a cleared runtime parameter, operating mode: ~ts", [OpMode])
9195
end.
9296

9397
%%----------------------------------------------------------------------------

deps/rabbitmq_shovel/src/rabbit_shovel_sup.erl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ start_link() ->
2121
end.
2222

2323
init([Configurations]) ->
24-
IsStandard = rabbit_shovel_operating_mode:is_standard(),
25-
StaticShovelSpecs = make_child_specs(IsStandard, Configurations),
24+
OpMode = rabbit_shovel_operating_mode:operating_mode(),
25+
StaticShovelSpecs = make_child_specs(OpMode, Configurations),
2626
Len = dict:size(Configurations),
2727
ChildSpecs = [
2828
#{
@@ -46,10 +46,8 @@ init([Configurations]) ->
4646
Opts = #{strategy => one_for_one, intensity => 2 * Len, period => 2},
4747
{ok, {Opts, ChildSpecs}}.
4848

49-
make_child_specs(false = _StandardOperatingMode, _Configurations) ->
50-
%% when operating in a non-standard mode, do not start any shovels
51-
[];
52-
make_child_specs(true, Configurations) ->
49+
50+
make_child_specs(standard, Configurations) ->
5351
dict:fold(
5452
fun (ShovelName, ShovelConfig, Acc) ->
5553
[
@@ -63,7 +61,10 @@ make_child_specs(true, Configurations) ->
6361
}
6462
| Acc
6563
]
66-
end, [], Configurations).
64+
end, [], Configurations);
65+
make_child_specs(_NonStandardOpMode, _Configurations) ->
66+
%% when operating in a non-standard mode, do not start any shovels
67+
[].
6768

6869
parse_configuration(undefined) ->
6970
{ok, dict:new()};

0 commit comments

Comments
 (0)