fix(resource): keep `auto_retry` in `disconnected` state
Automatic retries should be maintained even in `disconnected` state without any state transition.
This commit is contained in:
parent
7c4ea38c06
commit
62ecf6f545
|
@ -384,9 +384,33 @@ handle_event(EventType, EventData, State, Data) ->
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
insert_cache(ResId, Group, Data = #data{manager_id = MgrId}) ->
|
insert_cache(ResId, Group, Data = #data{manager_id = MgrId}) ->
|
||||||
case get_owner(ResId) of
|
case get_owner(ResId) of
|
||||||
not_found -> ets:insert(?ETS_TABLE, {ResId, Group, Data});
|
not_found ->
|
||||||
MgrId -> ets:insert(?ETS_TABLE, {ResId, Group, Data});
|
?SLOG(
|
||||||
_ -> self() ! quit
|
debug,
|
||||||
|
#{
|
||||||
|
msg => resource_owner_not_found,
|
||||||
|
resource_id => ResId,
|
||||||
|
action => auto_insert_cache
|
||||||
|
}
|
||||||
|
),
|
||||||
|
ets:insert(?ETS_TABLE, {ResId, Group, Data});
|
||||||
|
MgrId ->
|
||||||
|
?SLOG(
|
||||||
|
debug,
|
||||||
|
#{
|
||||||
|
msg => resource_owner_matched,
|
||||||
|
resource_id => ResId,
|
||||||
|
action => reinsert_cache
|
||||||
|
}
|
||||||
|
),
|
||||||
|
ets:insert(?ETS_TABLE, {ResId, Group, Data});
|
||||||
|
_ ->
|
||||||
|
?SLOG(error, #{
|
||||||
|
msg => get_resource_owner_failed,
|
||||||
|
resource_id => ResId,
|
||||||
|
action => quit_rusource
|
||||||
|
}),
|
||||||
|
self() ! quit
|
||||||
end.
|
end.
|
||||||
|
|
||||||
read_cache(ResId) ->
|
read_cache(ResId) ->
|
||||||
|
@ -425,12 +449,14 @@ get_owner(ResId) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
handle_disconnected_state_enter(Data) ->
|
handle_disconnected_state_enter(Data) ->
|
||||||
|
{next_state, disconnected, Data, retry_actions(Data)}.
|
||||||
|
|
||||||
|
retry_actions(Data) ->
|
||||||
case maps:get(auto_restart_interval, Data#data.opts, ?AUTO_RESTART_INTERVAL) of
|
case maps:get(auto_restart_interval, Data#data.opts, ?AUTO_RESTART_INTERVAL) of
|
||||||
undefined ->
|
undefined ->
|
||||||
{next_state, disconnected, Data};
|
[];
|
||||||
RetryInterval ->
|
RetryInterval ->
|
||||||
Actions = [{state_timeout, RetryInterval, auto_retry}],
|
[{state_timeout, RetryInterval, auto_retry}]
|
||||||
{next_state, disconnected, Data, Actions}
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
handle_remove_event(From, ClearMetrics, Data) ->
|
handle_remove_event(From, ClearMetrics, Data) ->
|
||||||
|
@ -461,7 +487,7 @@ start_resource(Data, From) ->
|
||||||
%% Keep track of the error reason why the connection did not work
|
%% Keep track of the error reason why the connection did not work
|
||||||
%% so that the Reason can be returned when the verification call is made.
|
%% so that the Reason can be returned when the verification call is made.
|
||||||
UpdatedData = Data#data{error = Reason},
|
UpdatedData = Data#data{error = Reason},
|
||||||
Actions = maybe_reply([], From, Err),
|
Actions = maybe_reply(retry_actions(UpdatedData), From, Err),
|
||||||
{next_state, disconnected, UpdatedData, Actions}
|
{next_state, disconnected, UpdatedData, Actions}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue