Fix conf parse bug (#2296)

Prior to this change, there are some config entry which is not parsed
correctly. So if user modify config such as reconnect_interval for
bridge, the new config can not be taken into effect.
This commit is contained in:
Gilbert 2019-03-11 16:31:21 +08:00 committed by GitHub
parent ad74772191
commit 93162c52b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 10 deletions

View File

@ -1697,23 +1697,31 @@ end}.
Cfg#{reconnect_delay_ms => Ms};
Tr(max_inflight, Count, Cfg) ->
Cfg#{max_inflight_batches => Count};
Tr(proto_ver, Ver, Cfg) ->
Cfg#{proto_ver =>
case Ver of
mqttv3 -> v3;
mqttv4 -> v4;
mqttv5 -> v5;
_ -> v4
end};
Tr(Key, Value, Cfg) ->
Cfg#{Key => Value}
end,
maps:to_list(
lists:foldl(
C = lists:foldl(
fun({["bridge", Name, Opt], Val}, Acc) ->
%% e.g #{aws => [{OptKey, OptVal}]}
Init = [{list_to_atom(Opt), Val},
{connect_module, ConnMod(Name)},
{subscriptions, Subscriptions(Name)},
{queue, Queue(Name)}
],
C = maps:update_with(list_to_atom(Name),
fun(Opts) -> Merge(list_to_atom(Opt), Val, Opts) end, Init, Acc),
maps:fold(Translate, #{}, C);
{queue, Queue(Name)}],
maps:update_with(list_to_atom(Name), fun(Opts) -> Merge(list_to_atom(Opt), Val, Opts) end, Init, Acc);
(_, Acc) -> Acc
end, #{}, lists:usort(cuttlefish_variable:filter_by_prefix("bridge.", Conf))))
end, #{}, lists:usort(cuttlefish_variable:filter_by_prefix("bridge.", Conf))),
C1 = maps:map(fun(Bn, Bc) ->
maps:to_list(maps:fold(Translate, #{}, maps:from_list(Bc)))
end, C),
maps:to_list(C1)
end}.
%%--------------------------------------------------------------------
@ -1952,4 +1960,4 @@ end}.
[{check_interval, cuttlefish:conf_get("vm_mon.check_interval", Conf)},
{process_high_watermark, cuttlefish:conf_get("vm_mon.process_high_watermark", Conf)},
{process_low_watermark, cuttlefish:conf_get("vm_mon.process_low_watermark", Conf)}]
end}.
end}.

View File

@ -29,4 +29,3 @@
{plugins, [coveralls]}.
{profiles, [{test, [{deps, [{meck, "0.8.13"}]}]}]}.