style: use a macro for 'catch'

This commit is contained in:
Zaiming (Stone) Shi 2022-03-25 08:21:50 +01:00
parent ee1b826d2a
commit 793add0219
1 changed files with 13 additions and 4 deletions

View File

@ -27,6 +27,17 @@
code_change/3 code_change/3
]). ]).
-define(OK(EXPR),
(fun() ->
try
_ = EXPR,
ok
catch
_:_ -> ok
end
end)()
).
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
%% API %% API
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
@ -90,11 +101,9 @@ connection_quota_early_alarm({ok, #{max_connections := Max}}) when is_integer(Ma
Message = iolist_to_binary([ Message = iolist_to_binary([
"License: live connection number exceeds ", HighPercent, "%" "License: live connection number exceeds ", HighPercent, "%"
]), ]),
catch emqx_alarm:activate(license_quota, #{high_watermark => HighPercent}, Message) ?OK(emqx_alarm:activate(license_quota, #{high_watermark => HighPercent}, Message))
end, end,
Count < Max * Low andalso Count < Max * Low andalso ?OK(emqx_alarm:deactivate(license_quota));
catch emqx_alarm:deactivate(license_quota),
ok;
connection_quota_early_alarm(_Limits) -> connection_quota_early_alarm(_Limits) ->
ok. ok.