6934c592 by 周伟奇

fix bug

1 parent b34cd942
......@@ -6,6 +6,7 @@ import base64
import signal
import requests
import traceback
from datetime import datetime
from django.core.management import BaseCommand
from multiprocessing import Process
......@@ -57,7 +58,7 @@ class Command(BaseCommand, LoggerMixin):
@staticmethod
def get_path(name, img_output_dir, wb_output_dir, pdf_output_dir):
time_stamp = int(time.time())
time_stamp = datetime.now().strftime('%Y-%m-%d_%H:%M:%S')
new_name = '{0}_{1}'.format(time_stamp, name)
img_save_path = os.path.join(img_output_dir, new_name)
pdf_save_path = os.path.join(pdf_output_dir, new_name)
......
......@@ -365,13 +365,17 @@ class Command(BaseCommand, LoggerMixin):
def pdf_2_img_2_queue(self, img_queue, todo_count_dict, lock):
while self.switch:
try:
# 1. 从队列获取文件信息
doc, business_type, task_str = self.get_doc_info()
# 队列为空时的处理
if doc is None:
time.sleep(self.sleep_time_doc_get)
continue
except Exception as e:
self.cronjob_log.error('{0} [process failed (get doc into)] [error={1}]'.format(
self.log_base, traceback.format_exc()))
else:
try:
# 2. 从EDMS获取PDF文件
doc_data_path = os.path.join(self.data_dir, business_type, consts.TMP_DIR_NAME, str(doc.id))
......@@ -418,6 +422,9 @@ class Command(BaseCommand, LoggerMixin):
continue
else:
self.cronjob_log.info('{0} [img_2_ocr_1] [get img] [img_path={1}]'.format(self.log_base, img_path))
for times in range(consts.RETRY_TIMES):
try:
with open(img_path, 'rb') as f:
base64_data = base64.b64encode(f.read())
# 获取解码后的base64值
......@@ -426,8 +433,6 @@ class Command(BaseCommand, LoggerMixin):
"file": file_data
}
for times in range(consts.RETRY_TIMES):
try:
start_time = time.time()
ocr_1_response = requests.post(url, json=json_data_1)
if ocr_1_response.status_code != 200:
......@@ -447,6 +452,7 @@ class Command(BaseCommand, LoggerMixin):
self.cronjob_log.warn('{0} [ocr_1 failed] [img_path={1}]'.format(self.log_base, img_path))
# continue
try:
del json_data_1
# /data/bmw-ocr-data/AFC/tmp/6/img/page_0_img_0.jpeg
# AFC_2
......@@ -463,6 +469,9 @@ class Command(BaseCommand, LoggerMixin):
del todo_count_dict[task_str]
else:
todo_count_dict[task_str] = todo_count - 1
except Exception as e:
self.cronjob_log.error('{0} [process failed (store ocr res)] [img_path={1}] [error={2}]'.format(
self.log_base, img_path, traceback.format_exc()))
def res_2_wb(self, res_dict, finish_queue, lock):
while True:
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!