From 7c1c5bf5a049a66a35b02092f5a07360ae8e6cc0 Mon Sep 17 00:00:00 2001 From: Franklin-F Date: Sun, 18 May 2025 13:17:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E9=87=8D=E8=AF=95?= =?UTF-8?q?=E6=9C=BA=E5=88=B6=E4=BB=A5=E5=A4=84=E7=90=86=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=B9=B6=E5=86=99=E5=85=A5=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- retry_error_records.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 retry_error_records.py diff --git a/retry_error_records.py b/retry_error_records.py new file mode 100644 index 0000000..e61e67c --- /dev/null +++ b/retry_error_records.py @@ -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)