chore: use macros for connector and action status atoms
This commit is contained in:
parent
25a88ccd04
commit
cfad0923cf
|
@ -88,7 +88,9 @@ on_stop(InstanceId, _State) ->
|
||||||
emqx_resource_pool:stop(InstanceId).
|
emqx_resource_pool:stop(InstanceId).
|
||||||
|
|
||||||
-spec on_get_status(resource_id(), state()) ->
|
-spec on_get_status(resource_id(), state()) ->
|
||||||
connected | disconnected | {disconnected, state(), {unhealthy_target, string()}}.
|
?status_connected
|
||||||
|
| ?status_disconnected
|
||||||
|
| {?status_disconnected, state(), {unhealthy_target, string()}}.
|
||||||
on_get_status(_InstanceId, #{pool_name := Pool} = State) ->
|
on_get_status(_InstanceId, #{pool_name := Pool} = State) ->
|
||||||
case
|
case
|
||||||
emqx_resource_pool:health_check_workers(
|
emqx_resource_pool:health_check_workers(
|
||||||
|
@ -99,15 +101,15 @@ on_get_status(_InstanceId, #{pool_name := Pool} = State) ->
|
||||||
)
|
)
|
||||||
of
|
of
|
||||||
{ok, Values} ->
|
{ok, Values} ->
|
||||||
AllOk = lists:all(fun(S) -> S =:= {ok, connected} end, Values),
|
AllOk = lists:all(fun(S) -> S =:= {ok, ?status_connected} end, Values),
|
||||||
case AllOk of
|
case AllOk of
|
||||||
true ->
|
true ->
|
||||||
connected;
|
?status_connected;
|
||||||
false ->
|
false ->
|
||||||
Unhealthy = lists:any(fun(S) -> S =:= {error, unhealthy_target} end, Values),
|
Unhealthy = lists:any(fun(S) -> S =:= {error, unhealthy_target} end, Values),
|
||||||
case Unhealthy of
|
case Unhealthy of
|
||||||
true -> {disconnected, State, {unhealthy_target, ?TOPIC_MESSAGE}};
|
true -> {?status_disconnected, State, {unhealthy_target, ?TOPIC_MESSAGE}};
|
||||||
false -> disconnected
|
false -> ?status_disconnected
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
|
@ -116,7 +118,7 @@ on_get_status(_InstanceId, #{pool_name := Pool} = State) ->
|
||||||
state => State,
|
state => State,
|
||||||
reason => Reason
|
reason => Reason
|
||||||
}),
|
}),
|
||||||
disconnected
|
?status_disconnected
|
||||||
end.
|
end.
|
||||||
|
|
||||||
on_add_channel(
|
on_add_channel(
|
||||||
|
@ -176,15 +178,15 @@ on_get_channel_status(
|
||||||
)
|
)
|
||||||
of
|
of
|
||||||
{ok, Values} ->
|
{ok, Values} ->
|
||||||
AllOk = lists:all(fun(S) -> S =:= {ok, connected} end, Values),
|
AllOk = lists:all(fun(S) -> S =:= {ok, ?status_connected} end, Values),
|
||||||
case AllOk of
|
case AllOk of
|
||||||
true ->
|
true ->
|
||||||
connected;
|
?status_connected;
|
||||||
false ->
|
false ->
|
||||||
Unhealthy = lists:any(fun(S) -> S =:= {error, unhealthy_target} end, Values),
|
Unhealthy = lists:any(fun(S) -> S =:= {error, unhealthy_target} end, Values),
|
||||||
case Unhealthy of
|
case Unhealthy of
|
||||||
true -> {disconnected, {unhealthy_target, ?TOPIC_MESSAGE}};
|
true -> {?status_disconnected, {unhealthy_target, ?TOPIC_MESSAGE}};
|
||||||
false -> disconnected
|
false -> ?status_disconnected
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
|
@ -193,7 +195,7 @@ on_get_channel_status(
|
||||||
state => State,
|
state => State,
|
||||||
reason => Reason
|
reason => Reason
|
||||||
}),
|
}),
|
||||||
disconnected
|
?status_disconnected
|
||||||
end.
|
end.
|
||||||
|
|
||||||
on_get_channels(ResId) ->
|
on_get_channels(ResId) ->
|
||||||
|
|
Loading…
Reference in New Issue