优化错误日志及重试机制

This commit is contained in:
2024-07-23 09:27:59 +08:00
parent ee86bb4e74
commit bcd9f94daf
9 changed files with 64 additions and 52 deletions

View File

@@ -9,10 +9,6 @@ PHHD_BATCH_SIZE = 20
SLEEP_MINUTES = 5
# 是否发送异常提醒邮件
SEND_ERROR_EMAIL = True
# 备份原图的尝试次数
COPY_TRY_TIMES = 3
# 上传新图的尝试次数
UPLOAD_TRY_TIMES = 3
"""
关键词配置

View File

@@ -7,8 +7,7 @@ from sqlalchemy import update, and_
from db import MysqlSession
from db.mysql import ZxPhrec, ZxPhhd
from photo_mask import OCR, PHHD_BATCH_SIZE, SLEEP_MINUTES, COPY_TRY_TIMES, UPLOAD_TRY_TIMES, NAME_KEYS, \
ID_CARD_NUM_KEYS
from photo_mask import OCR, PHHD_BATCH_SIZE, SLEEP_MINUTES, NAME_KEYS, ID_CARD_NUM_KEYS
from ucloud import BUCKET, ufile
from util import image_util, util
@@ -177,18 +176,12 @@ def photo_mask(pk_phhd, name, id_card_num):
# 如果涂抹了要备份以及更新
if is_masked:
for i in range(COPY_TRY_TIMES):
is_copy_success = ufile.copy_file(BUCKET, phrec.cfjaddress, "drg2015", phrec.cfjaddress)
if is_copy_success:
break
ufile.copy_file(BUCKET, phrec.cfjaddress, "drg2015", phrec.cfjaddress)
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file:
cv2.imwrite(temp_file.name, image)
try:
for i in range(UPLOAD_TRY_TIMES):
is_upload_success = ufile.upload_file(phrec.cfjaddress, temp_file.name)
if is_upload_success:
break
ufile.upload_file(phrec.cfjaddress, temp_file.name)
except Exception as e:
logging.error("上传图片出错", exc_info=e)
finally: