From 990a622cf629819a509cccdf7446c130063a9084 Mon Sep 17 00:00:00 2001 From: passthem Date: Mon, 13 Oct 2025 11:48:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=BA=9B=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=94=A8=E4=BA=8E=E8=B0=83=E8=AF=95=20Notify=20?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- konabot/plugins/simple_notify/__init__.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/konabot/plugins/simple_notify/__init__.py b/konabot/plugins/simple_notify/__init__.py index 09e1940..d4b92a6 100644 --- a/konabot/plugins/simple_notify/__init__.py +++ b/konabot/plugins/simple_notify/__init__.py @@ -107,11 +107,16 @@ async def notify_now(notify: Notify): return True -async def create_notify_task(notify: Notify, fail2remove: bool = True): +def create_notify_task(notify: Notify, fail2remove: bool = True): async def mission(): begin_time = datetime.datetime.now() if begin_time < notify.notify_time: await asyncio.sleep((notify.notify_time - begin_time).total_seconds()) + else: + logger.warning( + f"期望在 {notify.notify_time} 在平台 {notify.platform} {notify.target_env}" + f"{notify.target} 的代办通知 {notify.notify_msg} 已经超时,将会直接通知!" + ) res = await notify_now(notify) if fail2remove or res: await DATA_FILE_LOCK.acquire() @@ -204,16 +209,20 @@ async def _(): return NOTIFIED_FLAG["task_added"] = True + logger.info("第一次探测到 Bot 连接,等待 10 秒后开始通知") await asyncio.sleep(10) await DATA_FILE_LOCK.acquire() - tasks = [] + + tasks: set[asyncio.Task[Any]] = set() cfg = load_notify_config() if cfg.version == 1: cfg.version = 2 else: for notify in cfg.notifies: - tasks.append(create_notify_task(notify, fail2remove=False)) + task = create_notify_task(notify, fail2remove=False) + tasks.add(task) + task.add_done_callback(lambda self: tasks.remove(self)) DATA_FILE_LOCK.release() await asyncio.gather(*tasks)