Commit e012b51 1 parent 2859a09 commit e012b51 Copy full SHA for e012b51
File tree 1 file changed +11
-6
lines changed
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
3
1
import logging
4
-
5
- import click
2
+ from datetime import datetime , timezone
3
+ from time import sleep
6
4
7
5
import aw_client
6
+ import click
8
7
from aw_core import Event
9
8
from aw_watcher_afk .listeners import KeyboardListener , MouseListener
10
9
@@ -23,7 +22,7 @@ def main(testing: bool):
23
22
bucket_name = "{}_{}" .format (client .client_name , client .client_hostname )
24
23
eventtype = "os.hid.input"
25
24
client .create_bucket (bucket_name , eventtype , queued = False )
26
- poll_time = 1
25
+ poll_time = 5
27
26
28
27
keyboard = KeyboardListener ()
29
28
keyboard .start ()
@@ -34,7 +33,13 @@ def main(testing: bool):
34
33
35
34
while True :
36
35
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
+
38
43
now = datetime .now (tz = timezone .utc )
39
44
40
45
# 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