fix: keep pending_uids until TG send completes to prevent duplicate processing

This commit is contained in:
2026-07-12 23:51:45 +08:00
parent 87e4b0b01e
commit bbc43f8972

11
main.py
View File

@@ -87,7 +87,7 @@ def _ai_processor(cfg):
_tg_queue.put(info)
except Exception as e:
logger.error(f"AI 处理邮件失败: {e}", exc_info=True)
finally:
# AI 失败也要移除 pending否则永远卡住
with _pending_lock:
_pending_uids.discard(mail.uid)
@@ -107,10 +107,19 @@ def _tg_worker(cfg):
try:
info = _tg_queue.get_nowait()
tg_send_and_mark(cfg, info)
# 发送并标记已读成功后才移除 pending
with _pending_lock:
_pending_uids.discard(info["uid"])
except queue_module.Empty:
break
except Exception as e:
logger.error(f"TG 发送失败: {e}", exc_info=True)
# 发送失败也要移除 pending避免永久阻塞
try:
with _pending_lock:
_pending_uids.discard(info["uid"])
except Exception:
pass
if _running:
time.sleep(1)