WIP: pre/post_hibernate
Peer Discovery AWS Integration Test / Integration Test (push) Has been cancelled Details

This commit is contained in:
Michal Kuratczyk 2024-09-05 11:54:01 +02:00 committed by Michal Kuratczyk
parent 35486d2876
commit 04144fd302
No known key found for this signature in database
1 changed files with 28 additions and 28 deletions

View File

@ -756,20 +756,20 @@ handle_info({update_user_state, User}, State = #ch{cfg = Cfg}) ->
noreply(State#ch{cfg = Cfg#conf{user = User}}). noreply(State#ch{cfg = Cfg#conf{user = User}}).
handle_pre_hibernate(State0) -> %handle_pre_hibernate(State0) ->
ok = clear_permission_cache(), % ok = clear_permission_cache(),
State = maybe_cancel_tick_timer(State0), % State = maybe_cancel_tick_timer(State0),
rabbit_event:if_enabled( % rabbit_event:if_enabled(
State, #ch.stats_timer, % State, #ch.stats_timer,
fun () -> emit_stats(State, % fun () -> emit_stats(State,
[{idle_since, % [{idle_since,
os:system_time(millisecond)}]) % os:system_time(millisecond)}])
end), % end),
{hibernate, rabbit_event:stop_stats_timer(State, #ch.stats_timer)}. % {hibernate, rabbit_event:stop_stats_timer(State, #ch.stats_timer)}.
%
handle_post_hibernate(State0) -> %handle_post_hibernate(State0) ->
State = init_tick_timer(State0), % State = init_tick_timer(State0),
{noreply, State}. % {noreply, State}.
terminate(_Reason, terminate(_Reason,
State = #ch{cfg = #conf{user = #user{username = Username}}, State = #ch{cfg = #conf{user = #user{username = Username}},
@ -2654,20 +2654,20 @@ init_tick_timer(State) ->
reset_tick_timer(State) -> reset_tick_timer(State) ->
State#ch{tick_timer = undefined}. State#ch{tick_timer = undefined}.
maybe_cancel_tick_timer(#ch{tick_timer = undefined} = State) -> %maybe_cancel_tick_timer(#ch{tick_timer = undefined} = State) ->
State; % State;
maybe_cancel_tick_timer(#ch{tick_timer = TRef, %maybe_cancel_tick_timer(#ch{tick_timer = TRef,
unacked_message_q = UMQ} = State) -> % unacked_message_q = UMQ} = State) ->
case ?QUEUE:len(UMQ) of % case ?QUEUE:len(UMQ) of
0 -> % 0 ->
%% we can only cancel the tick timer if the unacked messages % %% we can only cancel the tick timer if the unacked messages
%% queue is empty. % %% queue is empty.
_ = erlang:cancel_timer(TRef), % _ = erlang:cancel_timer(TRef),
State#ch{tick_timer = undefined}; % State#ch{tick_timer = undefined};
_ -> % _ ->
%% let the timer continue % %% let the timer continue
State % State
end. % end.
now_millis() -> now_millis() ->
erlang:monotonic_time(millisecond). erlang:monotonic_time(millisecond).