;hY.,T r d Z ddlZddlmZmZ ddlmZ ee Z G d d Z e Z
dS )zThis module implement inactivity tracker for ImunifyAV to automaticaly
shutdown the process when it is idle for certain time (no RPC calls and
long running tasks).
N)contextmanagersuppress) getLoggerc X e Zd Zd Zd Zed Zd Zd Zd Z d Z
ded d
fdZd
S )InactivityTrackerc ` t j | _ d| _ g | _ d| _ d S )Nr )time monotonic_last_action_timestamp_long_action_counter_long_actions_list_timeoutselfs S/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/api/inactivity.py__init__zInactivityTracker.__init__
s- &*n&6&6#$%!"$
c j d t j | j z
| j S )Nz0Time from last action is {:.0f}, long actions {})formatr r
r r
r s r __str__zInactivityTracker.__str__ s3 AHHNt::#
r c # K | | d V | | d S # | | w xY wN)startstopr names r taskzInactivityTracker.task sM
4 EEEIIdOOOOODIIdOOOOs 4 Ac 6 t j | _ d S r )r r
r r s r reset_timerzInactivityTracker.reset_timer! s &*n&6&6###r c | xj dz
c_ | j | | d S N )r r
appendr r s r r zInactivityTracker.start$ sE !!Q&!!&&t,,,r c | xj dz c_ t t 5 | j | d d d n# 1 swxY w Y | d S r! )r r
ValueErrorr
remover r s r r zInactivityTracker.stop) s !!Q&!!
j
!
! 1 1#**4000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1s AAAc Z | j o#| j | j z t j k S r )r r r r r
r s r
is_timeoutzInactivityTracker.is_timeout/ s/ --
'$-74>;K;KK
r timeoutreturnNc || _ d S r )r )r r) s r set_timeoutzInactivityTracker.set_timeout4 s
r )
__name__
__module____qualname__r r r r r r r r( intr, r r r r s
^7 7 7
3 4 r r )__doc__r
contextlibr r loggingr r- loggerr trackr1 r r