Skip to content

Commit

Permalink
Improve sync interval precision
Browse files Browse the repository at this point in the history
  • Loading branch information
itssimon committed Dec 30, 2023
1 parent dd3932b commit 51679ed
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion apitally/client/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ async def _run_sync_loop(self) -> None:
first_iteration = True
while not self._stop_sync_loop:
try:
time_start = time.perf_counter()
async with self.get_http_client() as client:
tasks = [self.send_requests_data(client)]
if self.sync_api_keys:
tasks.append(self.get_keys(client))
if not self._app_info_sent and not first_iteration:
tasks.append(self.send_app_info(client))
await asyncio.gather(*tasks)
await asyncio.sleep(self.sync_interval)
time_elapsed = time.perf_counter() - time_start
await asyncio.sleep(self.sync_interval - time_elapsed)
except Exception as e: # pragma: no cover
logger.exception(e)
first_iteration = False
Expand Down
2 changes: 1 addition & 1 deletion apitally/client/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _run_sync_loop(self) -> None:
while not self._stop_sync_loop.is_set():
try:
now = time.time()
if (now - last_sync_time) > self.sync_interval:
if (now - last_sync_time) >= self.sync_interval:
with requests.Session() as session:
if self.sync_api_keys:
self.get_keys(session)
Expand Down

0 comments on commit 51679ed

Please sign in to comment.