spoolman: use loop time rather than datetime

The loop time is monotonic and can't be affected by
changes to the system clock.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2024-01-17 14:15:21 -05:00
parent b836d618c9
commit e9ad278286
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
1 changed files with 3 additions and 4 deletions

View File

@ -6,7 +6,6 @@
from __future__ import annotations
import asyncio
import datetime
import logging
import re
import tornado.websocket as tornado_ws
@ -39,7 +38,7 @@ class SpoolManager:
self.eventloop = self.server.get_event_loop()
self._get_spoolman_urls(config)
self.sync_rate_seconds = config.getint("sync_rate", default=5, minval=1)
self.last_sync_time = datetime.datetime.now()
self.last_sync_time = 0.
self.extruded_lock = asyncio.Lock()
self.spoolman_ws: Optional[WebSocketClientConnection] = None
self.connection_task: Optional[asyncio.Task] = None
@ -232,9 +231,9 @@ class SpoolManager:
self.extruded += epos - self._highest_epos
self._highest_epos = epos
now = datetime.datetime.now()
now = self.eventloop.get_loop_time()
difference = now - self.last_sync_time
if difference.total_seconds() > self.sync_rate_seconds:
if difference > self.sync_rate_seconds:
self.last_sync_time = now
logging.debug("Sync period elapsed, tracking usage")
await self.track_filament_usage()