File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed
Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change 1- from time import sleep
2- from datetime import datetime , timezone
31import logging
4-
5- import click
2+ from datetime import datetime , timezone
3+ from time import sleep
64
75import aw_client
6+ import click
87from aw_core import Event
98from aw_watcher_afk .listeners import KeyboardListener , MouseListener
109
@@ -23,7 +22,7 @@ def main(testing: bool):
2322 bucket_name = "{}_{}" .format (client .client_name , client .client_hostname )
2423 eventtype = "os.hid.input"
2524 client .create_bucket (bucket_name , eventtype , queued = False )
26- poll_time = 1
25+ poll_time = 5
2726
2827 keyboard = KeyboardListener ()
2928 keyboard .start ()
@@ -34,7 +33,13 @@ def main(testing: bool):
3433
3534 while True :
3635 last_run = now
37- sleep (poll_time )
36+
37+ # we want to ensure that the polling happens with a predictable cadence
38+ time_to_sleep = poll_time - datetime .now ().timestamp () % poll_time
39+ # ensure that the sleep time is between 0 and poll_time (if system time is changed, this might be negative)
40+ time_to_sleep = max (min (time_to_sleep , poll_time ), 0 )
41+ sleep (time_to_sleep )
42+
3843 now = datetime .now (tz = timezone .utc )
3944
4045 # If input: Send a heartbeat with data, ensure the span is correctly set, and don't use pulsetime.
You can’t perform that action at this time.
0 commit comments