添加一些日志用于调试 Notify 功能
This commit is contained in:
@ -107,11 +107,16 @@ async def notify_now(notify: Notify):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def create_notify_task(notify: Notify, fail2remove: bool = True):
|
def create_notify_task(notify: Notify, fail2remove: bool = True):
|
||||||
async def mission():
|
async def mission():
|
||||||
begin_time = datetime.datetime.now()
|
begin_time = datetime.datetime.now()
|
||||||
if begin_time < notify.notify_time:
|
if begin_time < notify.notify_time:
|
||||||
await asyncio.sleep((notify.notify_time - begin_time).total_seconds())
|
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)
|
res = await notify_now(notify)
|
||||||
if fail2remove or res:
|
if fail2remove or res:
|
||||||
await DATA_FILE_LOCK.acquire()
|
await DATA_FILE_LOCK.acquire()
|
||||||
@ -204,16 +209,20 @@ async def _():
|
|||||||
return
|
return
|
||||||
|
|
||||||
NOTIFIED_FLAG["task_added"] = True
|
NOTIFIED_FLAG["task_added"] = True
|
||||||
|
logger.info("第一次探测到 Bot 连接,等待 10 秒后开始通知")
|
||||||
|
|
||||||
await asyncio.sleep(10)
|
await asyncio.sleep(10)
|
||||||
await DATA_FILE_LOCK.acquire()
|
await DATA_FILE_LOCK.acquire()
|
||||||
tasks = []
|
|
||||||
|
tasks: set[asyncio.Task[Any]] = set()
|
||||||
cfg = load_notify_config()
|
cfg = load_notify_config()
|
||||||
if cfg.version == 1:
|
if cfg.version == 1:
|
||||||
cfg.version = 2
|
cfg.version = 2
|
||||||
else:
|
else:
|
||||||
for notify in cfg.notifies:
|
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()
|
DATA_FILE_LOCK.release()
|
||||||
|
|
||||||
await asyncio.gather(*tasks)
|
await asyncio.gather(*tasks)
|
||||||
|
|||||||
Reference in New Issue
Block a user