From 2ea00152414d38a266d6efb2019ef981aaf8f939 Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Thu, 5 Dec 2024 03:19:00 +0000 Subject: [PATCH] Update scheduler.py --- ovos_bus_client/util/scheduler.py | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/ovos_bus_client/util/scheduler.py b/ovos_bus_client/util/scheduler.py index f603339..c06b961 100644 --- a/ovos_bus_client/util/scheduler.py +++ b/ovos_bus_client/util/scheduler.py @@ -70,22 +70,13 @@ def __init__(self, bus, schedule_file: str = 'schedule.json', autostart: bool = self.events = {} self.event_lock = Lock() - clock_cache = get_xdg_cache_save_path("ovos_clock") - os.makedirs(clock_cache, exist_ok=True) - self.clock_cache = os.path.join(clock_cache, "ovos_clock_sync.ts") - self.last_sync = time.time() - if os.path.isfile(self.clock_cache): - with open(self.clock_cache) as f: - self.last_sync = float(f.read()) - else: - with open(self.clock_cache, "w") as f: - f.write(str(self.last_sync)) - self._dropped_events = 0 + # to check if its our first connection to the internet via clock_skew + self._last_sync = time.time() + self._dropped_events = 0 self._past_date = datetime.datetime(day=1, month=12, year=2024) - # Convert Unix timestamp to human-readable datetime - pretty_last_sync = datetime.datetime.fromtimestamp(self.last_sync).strftime("%Y-%m-%d %H:%M:%S") + pretty_last_sync = datetime.datetime.fromtimestamp(self._last_sync).strftime("%Y-%m-%d %H:%M:%S") LOG.debug(f"Last clock sync: {pretty_last_sync}") self.bus = bus @@ -214,7 +205,7 @@ def schedule_event(self, event: str, sched_time: float, context to send when the handler is called """ - if datetime.datetime.fromtimestamp(self.last_sync) < self._past_date: + if datetime.datetime.fromtimestamp(self._last_sync) < self._past_date: # this works around problems in raspOVOS images and other # systems without RTC that didnt sync clock with the internet yet # eg. issue demonstration without this: @@ -277,15 +268,13 @@ def remove_event(self, event: str): def handle_system_clock_sync(self, message: Message): # clock sync, are we in the past? - if datetime.datetime.fromtimestamp(self.last_sync) < self._past_date: + if datetime.datetime.fromtimestamp(self._last_sync) < self._past_date: LOG.warning(f"Clock was in the past!!! {self._dropped_events} scheduled events have been dropped") - self.last_sync = time.time() + self._last_sync = time.time() # Convert Unix timestamp to human-readable datetime - pretty_last_sync = datetime.datetime.fromtimestamp(self.last_sync).strftime("%Y-%m-%d %H:%M:%S") + pretty_last_sync = datetime.datetime.fromtimestamp(self._last_sync).strftime("%Y-%m-%d %H:%M:%S") LOG.info(f"clock sync: {pretty_last_sync}") - with open(self.clock_cache, "w") as f: - f.write(str(self.last_sync)) def remove_event_handler(self, message: Message): """