feat: 添加重试机制以处理错误记录并写入数据库

This commit is contained in:
晓丰 2025-05-18 13:17:39 +08:00
parent 7f60997a58
commit 7c1c5bf5a0

32
retry_error_records.py Normal file
View File

@ -0,0 +1,32 @@
import time
from DB import DBVidcon
def retry_error_records(poll_interval=10):
"""
持续检测 urgent_list_key list_key 队列一旦都为空就从 error_list_key 弹出一条记录
并调用 upsert_video 重试写入
"""
db = DBVidcon()
while True:
# 判断 urgent 和普通列表是否都为空
if db.queues_empty():
err = db.pop_error_item()
if err:
record = err
try:
print(f"[重试] 处理错误记录: {record}")
db.upsert_video(record)
db.flush()
print("[重试] 成功写入数据库")
except Exception as e:
print(f"[重试] 写入失败: {e}")
else:
time.sleep(poll_interval*poll_interval)
else:
time.sleep(poll_interval)
if __name__ == '__main__':
retry_error_records(poll_interval=10)