From e2245d86e15ed57b2115a3e7a58ca736e9a34dd6 Mon Sep 17 00:00:00 2001 From: Franklin-F Date: Fri, 27 Jun 2025 20:19:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9get=5Fsubsequent=5Fre?= =?UTF-8?q?port=5Fvideo=E6=96=B9=E6=B3=95=E4=BB=A5=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=BC=A0=E5=85=A5mid=E5=8F=82=E6=95=B0=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=B8=BB=E6=B5=81=E7=A8=8B=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DB.py | 6 ++-- report.py | 86 +++++++++++++++++++++++++++---------------------------- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/DB.py b/DB.py index eabfb25..277b1ac 100644 --- a/DB.py +++ b/DB.py @@ -354,7 +354,7 @@ class DBVidcon: return self.cursor.fetchall() @mysql_retry() - def get_subsequent_report_video(self): + def get_subsequent_report_video(self,did: int): sql = """ SELECT id, @@ -365,9 +365,9 @@ class DBVidcon: status = 2 AND subsequent_status = 1 AND report_time != '' - LIMIT 10 + AND mid = %s """ - self.cursor.execute(sql) + self.cursor.execute(sql,did) return self.cursor.fetchall() @mysql_retry() diff --git a/report.py b/report.py index d328198..c8ed3bf 100644 --- a/report.py +++ b/report.py @@ -73,46 +73,46 @@ last_subsequent_run = 0 MAIN_INTERVAL = 60 * 5 # 每 5 分钟执行一次 SUBSEQUENT_INTERVAL = 60 * 60 # 每 60 分钟执行一次 -d.test() -# while True: -# now = int(time.time()) -# -# # 处理主流程 -# if now - last_main_run >= MAIN_INTERVAL: -# last_main_run = now -# lis = db.item_report() -# if len(lis) > 0: -# for _, li in lis: -# print(li) -# logger.info(f"name:{li['name_title']},link:{li['link']} ") -# try: -# info, report_id, status, report_ts = d.process_ticket(li['name_title'], li['link']) -# subsequent_status = k.get(status, 1) -# db.update_fight_record_status( -# li['id'], report_id, 2, f"http://{ip}:5000/image/{info}", -# report_ts, subsequent_status, MACHINE_ID -# ) -# db.flush() -# except Exception as e: -# logger.logger.error(f"ID:{li['id']}, e:{e}") -# db.update_fight_record_status(li['id'], 0, 3, str(e), mid=MACHINE_ID) -# time.sleep(60) # 出错延迟 -# -# if now - last_subsequent_run >= SUBSEQUENT_INTERVAL and IsSubsequent: -# last_subsequent_run = now -# subsequent_list = db.get_subsequent_report_video() -# if len(subsequent_list) > 0: -# for li in subsequent_list: -# rs_id = li['id'] -# r_id = li['report_id'] -# logger.info(f"subsequent id:{rs_id},report_id:{r_id} ") -# # try: -# subsequent_status, info = d.report_follow_up(r_id) -# db.update_subsequent_status_by_id( -# rs_id, subsequent_status, f"http://{ip}:5000/image/{info}" -# ) -# # except Exception as e: -# # logger.logger.error(f"ID:{rs_id}, e:{e}") -# # db.update_subsequent_status_by_id(rs_id, 1, str(e)) -# time.sleep(5) # 避免频繁请求 -# time.sleep(5) + +while True: + now = int(time.time()) + + # 处理主流程 + if now - last_main_run >= MAIN_INTERVAL: + last_main_run = now + lis = db.item_report() + if len(lis) > 0: + for _, li in lis: + print(li) + logger.info(f"name:{li['name_title']},link:{li['link']} ") + try: + info, report_id, status, report_ts = d.process_ticket(li['name_title'], li['link']) + subsequent_status = k.get(status, 1) + db.update_fight_record_status( + li['id'], report_id, 2, f"http://{ip}:5000/image/{info}", + report_ts, subsequent_status, MACHINE_ID + ) + db.flush() + except Exception as e: + logger.logger.error(f"ID:{li['id']}, e:{e}") + db.update_fight_record_status(li['id'], 0, 3, str(e), mid=MACHINE_ID) + time.sleep(60) # 出错延迟 + + if now - last_subsequent_run >= SUBSEQUENT_INTERVAL and IsSubsequent: + last_subsequent_run = now + subsequent_list = db.get_subsequent_report_video(MACHINE_ID) + if len(subsequent_list) > 0: + for li in subsequent_list: + rs_id = li['id'] + r_id = li['report_id'] + logger.info(f"subsequent id:{rs_id},report_id:{r_id} ") + # try: + subsequent_status, info = d.report_follow_up(r_id) + db.update_subsequent_status_by_id( + rs_id, subsequent_status, f"http://{ip}:5000/image/{info}" + ) + # except Exception as e: + # logger.logger.error(f"ID:{rs_id}, e:{e}") + # db.update_subsequent_status_by_id(rs_id, 1, str(e)) + time.sleep(5) # 避免频繁请求 + time.sleep(5)