fix: add done_callback to SD timer task to catch background errors

This commit is contained in:
Денис Кривоченко
2026-07-30 23:16:36 +07:00
parent d3f6206113
commit c7e0fd8cc6
+3
View File
@@ -350,6 +350,7 @@ async def sd_module_handler(msg: Message):
if "timer_task" in session and not session["timer_task"].done(): if "timer_task" in session and not session["timer_task"].done():
session["timer_task"].cancel() session["timer_task"].cancel()
session["timer_task"] = asyncio.create_task(_wait_for_attachments_and_create(user_id, session)) session["timer_task"] = asyncio.create_task(_wait_for_attachments_and_create(user_id, session))
session["timer_task"].add_done_callback(lambda t: _on_sd_timer_done(t, user_id))
sd_workflow_logger.info(f"⏳ [SD] Timer started: waiting {ATTACHMENT_WAIT_TIMEOUT}s for potentially more attachments...") sd_workflow_logger.info(f"⏳ [SD] Timer started: waiting {ATTACHMENT_WAIT_TIMEOUT}s for potentially more attachments...")
return return
@@ -366,6 +367,7 @@ async def sd_module_handler(msg: Message):
if "timer_task" in session and not session["timer_task"].done(): if "timer_task" in session and not session["timer_task"].done():
session["timer_task"].cancel() session["timer_task"].cancel()
session["timer_task"] = asyncio.create_task(_wait_for_attachments_and_create(user_id, session)) session["timer_task"] = asyncio.create_task(_wait_for_attachments_and_create(user_id, session))
session["timer_task"].add_done_callback(lambda t: _on_sd_timer_done(t, user_id))
sd_workflow_logger.info(f"🔄 [SD] Timer reset due to user activity. Waiting another {ATTACHMENT_WAIT_TIMEOUT}s") sd_workflow_logger.info(f"🔄 [SD] Timer reset due to user activity. Waiting another {ATTACHMENT_WAIT_TIMEOUT}s")
return return
@@ -404,3 +406,4 @@ async def sd_module_handler(msg: Message):