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)