fix: keep pending_uids until TG send completes to prevent duplicate processing
This commit is contained in:
11
main.py
11
main.py
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user