fix: handle resource errors

This commit is contained in:
Stefan Strigler 2023-06-29 10:42:19 +02:00
parent 321fd53132
commit 14da61194e
1 changed files with 3 additions and 3 deletions

View File

@ -344,6 +344,7 @@ handle_action(RuleId, ActId, Selected, Envs) ->
}) })
end. end.
-define(IS_RES_DOWN(R), R == stopped; R == not_connected; R == not_found; R == unhealthy_target).
do_handle_action(RuleId, {bridge, BridgeType, BridgeName, ResId}, Selected, _Envs) -> do_handle_action(RuleId, {bridge, BridgeType, BridgeName, ResId}, Selected, _Envs) ->
?TRACE( ?TRACE(
"BRIDGE", "BRIDGE",
@ -356,6 +357,8 @@ do_handle_action(RuleId, {bridge, BridgeType, BridgeName, ResId}, Selected, _Env
of of
{error, Reason} when Reason == bridge_not_found; Reason == bridge_stopped -> {error, Reason} when Reason == bridge_not_found; Reason == bridge_stopped ->
throw(out_of_service); throw(out_of_service);
?RESOURCE_ERROR_M(R, _) when ?IS_RES_DOWN(R) ->
throw(out_of_service);
Result -> Result ->
Result Result
end; end;
@ -520,11 +523,8 @@ inc_action_metrics(RuleId, Result) ->
_ = do_inc_action_metrics(RuleId, Result), _ = do_inc_action_metrics(RuleId, Result),
Result. Result.
-define(IS_RES_DOWN(R), R == stopped; R == not_connected; R == not_found).
do_inc_action_metrics(RuleId, {error, {recoverable_error, _}}) -> do_inc_action_metrics(RuleId, {error, {recoverable_error, _}}) ->
emqx_metrics_worker:inc(rule_metrics, RuleId, 'actions.failed.out_of_service'); emqx_metrics_worker:inc(rule_metrics, RuleId, 'actions.failed.out_of_service');
do_inc_action_metrics(RuleId, ?RESOURCE_ERROR_M(R, _)) when ?IS_RES_DOWN(R) ->
emqx_metrics_worker:inc(rule_metrics, RuleId, 'actions.failed.out_of_service');
do_inc_action_metrics(RuleId, {error, {unrecoverable_error, _}}) -> do_inc_action_metrics(RuleId, {error, {unrecoverable_error, _}}) ->
emqx_metrics_worker:inc(rule_metrics, RuleId, 'actions.failed'); emqx_metrics_worker:inc(rule_metrics, RuleId, 'actions.failed');
do_inc_action_metrics(RuleId, R) -> do_inc_action_metrics(RuleId, R) ->