添加一些日志用于调试 Notify 功能

This commit is contained in:
2025-10-13 11:48:22 +08:00
parent 6144563d4d
commit 990a622cf6

View File

@ -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)