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}) ->
|
||||
case get_owner(ResId) of
|
||||
not_found -> ets:insert(?ETS_TABLE, {ResId, Group, Data});
|
||||
MgrId -> ets:insert(?ETS_TABLE, {ResId, Group, Data});
|
||||
_ -> self() ! quit
|
||||
not_found ->
|
||||
?SLOG(
|
||||
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.
|
||||
|
||||
read_cache(ResId) ->
|
||||
|
@ -425,12 +449,14 @@ get_owner(ResId) ->
|
|||
end.
|
||||
|
||||
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
|
||||
undefined ->
|
||||
{next_state, disconnected, Data};
|
||||
[];
|
||||
RetryInterval ->
|
||||
Actions = [{state_timeout, RetryInterval, auto_retry}],
|
||||
{next_state, disconnected, Data, Actions}
|
||||
[{state_timeout, RetryInterval, auto_retry}]
|
||||
end.
|
||||
|
||||
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
|
||||
%% so that the Reason can be returned when the verification call is made.
|
||||
UpdatedData = Data#data{error = Reason},
|
||||
Actions = maybe_reply([], From, Err),
|
||||
Actions = maybe_reply(retry_actions(UpdatedData), From, Err),
|
||||
{next_state, disconnected, UpdatedData, Actions}
|
||||
end.
|
||||
|
||||
|
|
Loading…
Reference in New Issue