Skip to content

Commit

Permalink
fix: increase default poll_time to 5s, sleep such that we get even in…
Browse files Browse the repository at this point in the history
…tervals
  • Loading branch information
ErikBjare committed Nov 22, 2023
1 parent 2859a09 commit e012b51
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/aw_watcher_input/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from time import sleep
from datetime import datetime, timezone
import logging

import click
from datetime import datetime, timezone
from time import sleep

import aw_client
import click
from aw_core import Event
from aw_watcher_afk.listeners import KeyboardListener, MouseListener

Expand All @@ -23,7 +22,7 @@ def main(testing: bool):
bucket_name = "{}_{}".format(client.client_name, client.client_hostname)
eventtype = "os.hid.input"
client.create_bucket(bucket_name, eventtype, queued=False)
poll_time = 1
poll_time = 5

keyboard = KeyboardListener()
keyboard.start()
Expand All @@ -34,7 +33,13 @@ def main(testing: bool):

while True:
last_run = now
sleep(poll_time)

# we want to ensure that the polling happens with a predictable cadence
time_to_sleep = poll_time - datetime.now().timestamp() % poll_time
# ensure that the sleep time is between 0 and poll_time (if system time is changed, this might be negative)
time_to_sleep = max(min(time_to_sleep, poll_time), 0)
sleep(time_to_sleep)

now = datetime.now(tz=timezone.utc)

# If input: Send a heartbeat with data, ensure the span is correctly set, and don't use pulsetime.
Expand Down

0 comments on commit e012b51

Please sign in to comment.