l#grdZddlZddlmZmZddlmZeeZGddZ 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) getLoggercXeZdZdZdZedZdZdZdZ dZ de d d fd Z d S) InactivityTrackerc`tj|_d|_g|_d|_dS)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#$%!"$ cjdtj|jz |jS)Nz,Time from last action is {}, long actions {})formatr r r r rs r__str__zInactivityTracker.__str__s3=DD N  t: :  #   rc#K|| dV||dS#||wxYwN)startstoprnames rtaskzInactivityTracker.tasksM 4  EEE IIdOOOOODIIdOOOOs 4A c6tj|_dSr)r r r rs r reset_timerzInactivityTracker.reset_timer!s&*n&6&6###rc|xjdz c_|j||dSN)r r appendrrs rrzInactivityTracker.start$sE !!Q&!! &&t,,, rc|xjdzc_tt5|j|dddn #1swxYwY|dSr!)r r ValueErrorr removerrs rrzInactivityTracker.stop)s !!Q&!! j ! ! 1 1  # * *4 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 sA  AAcZ|j o#|j|jztjkSr)r r rr r rs r is_timeoutzInactivityTracker.is_timeout/s/--  '$- 74>;K;K K rtimeoutreturnNc||_dSr)r)rr)s r set_timeoutzInactivityTracker.set_timeout4s  r) __name__ __module__ __qualname__rrrrrrrr(intr,rrrr s    ^777      3 4      rr) __doc__r contextlibrrloggingrr-loggerrtrackr1rrr7s //////// 8  ) ) ) ) ) ) ) ) X r