diff --git a/bot/main.py b/bot/main.py index ca6aa7e..cfa984d 100644 --- a/bot/main.py +++ b/bot/main.py @@ -1236,11 +1236,10 @@ def start_bot(bot_token, socks): ws_helper = WebSocketHelper(configWrap, klippy, notifier, timelapse, a_scheduler, rotating_handler) - a_scheduler.start() - loop = asyncio.get_event_loop() loop.create_task(ws_helper.run_forever_async()) + a_scheduler.start() a_scheduler.add_job( greeting_message, kwargs={"bot": bot_updater.bot}, diff --git a/bot/notifications.py b/bot/notifications.py index e7e0111..b5e65ac 100644 --- a/bot/notifications.py +++ b/bot/notifications.py @@ -341,7 +341,7 @@ def _schedule_notification(self, message: str = "", schedule: bool = False, fini self._sched.add_job( self._notify, kwargs={"message": mess, "silent": self._silent_progress, "group_only": self._group_only, "finish": finish}, - misfire_grace_time=None, + misfire_grace_time=180, coalesce=False, max_instances=6, replace_existing=False, diff --git a/bot/websocket_helper.py b/bot/websocket_helper.py index 66e45bf..3136c4a 100644 --- a/bot/websocket_helper.py +++ b/bot/websocket_helper.py @@ -338,13 +338,7 @@ async def websocket_to_message(self, ws_message): self._scheduler.remove_job("ws_reschedule") elif klippy_state in ["error", "shutdown", "startup"]: await self._klippy.set_connected(False) - self._scheduler.add_job( - self.reshedule, - "interval", - seconds=2, - id="ws_reschedule", - replace_existing=True, - ) + self._scheduler.add_job(self.reshedule, "interval", seconds=2, id="ws_reschedule", replace_existing=True, coalesce=True, misfire_grace_time=10) state_message = message_result["state_message"] if self._klippy.state_message != state_message and klippy_state != "startup": self._klippy.state_message = state_message @@ -352,13 +346,7 @@ async def websocket_to_message(self, ws_message): else: logger.error("UnKnown klippy state: %s", klippy_state) await self._klippy.set_connected(False) - self._scheduler.add_job( - self.reshedule, - "interval", - seconds=2, - id="ws_reschedule", - replace_existing=True, - ) + self._scheduler.add_job(self.reshedule, "interval", seconds=2, id="ws_reschedule", replace_existing=True, coalesce=True, misfire_grace_time=10) return if "devices" in message_result: @@ -375,13 +363,7 @@ async def websocket_to_message(self, ws_message): logger.warning("klippy disconnect detected with message: %s", json_message["method"]) await self.stop_all() await self._klippy.set_connected(False) - self._scheduler.add_job( - self.reshedule, - "interval", - seconds=2, - id="ws_reschedule", - replace_existing=True, - ) + self._scheduler.add_job(self.reshedule, "interval", seconds=2, id="ws_reschedule", replace_existing=True, coalesce=True, misfire_grace_time=10) if "params" not in json_message: return @@ -446,7 +428,7 @@ async def run_forever_async(self): ): try: self._ws = websocket - self._scheduler.add_job(self.reshedule, "interval", seconds=2, id="ws_reschedule", replace_existing=True) + self._scheduler.add_job(self.reshedule, "interval", seconds=2, id="ws_reschedule", replace_existing=True, coalesce=True, misfire_grace_time=10) # async for message in self._ws: # await self.websocket_to_message(message) diff --git a/scripts/requirements.txt b/scripts/requirements.txt index e0a9981..ed46059 100644 --- a/scripts/requirements.txt +++ b/scripts/requirements.txt @@ -1,5 +1,6 @@ aiolimiter==1.2.1 anyio==4.7.0 +APScheduler==3.10.4 emoji==2.14.0 ffmpegcv==0.3.15 idna==3.10 @@ -7,7 +8,7 @@ orjson==3.10.13 Pillow==11.1.0 ; python_version>='3.10' Pillow==10.4.0 ; python_version<='3.9' psutil==6.1.1 -python-telegram-bot[socks,http2,rate-limiter,callback-data,job-queue]==21.9 +python-telegram-bot[socks,http2,rate-limiter,callback-data,job-queue]==21.10 tzlocal==2.1 uvloop==0.21.0 ; platform_system != "Windows" websockets==14.1