fix: process one queued email per poll cycle to keep callbacks responsive

This commit is contained in:
2026-07-15 18:32:42 +08:00
parent 17514302f9
commit 2744d9dd77

28
main.py
View File

@@ -107,24 +107,24 @@ def _tg_worker(cfg):
except Exception as e: except Exception as e:
logger.error(f"TG 轮询错误: {e}", exc_info=True) logger.error(f"TG 轮询错误: {e}", exc_info=True)
while _running: # 每轮只处理一封待发邮件,然后立刻回去 poll Telegram
try:
info = _tg_queue.get_nowait()
tg_send_and_mark(cfg, info)
uid_str = info["uid"].decode("utf-8", errors="replace") if isinstance(info["uid"], bytes) else str(info["uid"])
mark_sent(uid_str)
except queue_module.Empty:
pass
except Exception as e:
logger.error(f"TG 发送失败: {e}", exc_info=True)
try: try:
info = _tg_queue.get_nowait()
tg_send_and_mark(cfg, info)
uid_str = info["uid"].decode("utf-8", errors="replace") if isinstance(info["uid"], bytes) else str(info["uid"]) uid_str = info["uid"].decode("utf-8", errors="replace") if isinstance(info["uid"], bytes) else str(info["uid"])
mark_sent(uid_str) mark_failed(uid_str)
except queue_module.Empty: except Exception:
break pass
except Exception as e:
logger.error(f"TG 发送失败: {e}", exc_info=True)
try:
uid_str = info["uid"].decode("utf-8", errors="replace") if isinstance(info["uid"], bytes) else str(info["uid"])
mark_failed(uid_str)
except Exception:
pass
if _running: if _running:
_shutdown_event.wait(1) _shutdown_event.wait(0.2)
def main(): def main():