fix bug
Showing
2 changed files
with
14 additions
and
4 deletions
... | @@ -6,6 +6,7 @@ import base64 | ... | @@ -6,6 +6,7 @@ import base64 |
6 | import signal | 6 | import signal |
7 | import requests | 7 | import requests |
8 | import traceback | 8 | import traceback |
9 | from datetime import datetime | ||
9 | from django.core.management import BaseCommand | 10 | from django.core.management import BaseCommand |
10 | from multiprocessing import Process | 11 | from multiprocessing import Process |
11 | 12 | ||
... | @@ -57,7 +58,7 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -57,7 +58,7 @@ class Command(BaseCommand, LoggerMixin): |
57 | 58 | ||
58 | @staticmethod | 59 | @staticmethod |
59 | def get_path(name, img_output_dir, wb_output_dir, pdf_output_dir): | 60 | def get_path(name, img_output_dir, wb_output_dir, pdf_output_dir): |
60 | time_stamp = int(time.time()) | 61 | time_stamp = datetime.now().strftime('%Y-%m-%d_%H:%M:%S') |
61 | new_name = '{0}_{1}'.format(time_stamp, name) | 62 | new_name = '{0}_{1}'.format(time_stamp, name) |
62 | img_save_path = os.path.join(img_output_dir, new_name) | 63 | img_save_path = os.path.join(img_output_dir, new_name) |
63 | pdf_save_path = os.path.join(pdf_output_dir, new_name) | 64 | pdf_save_path = os.path.join(pdf_output_dir, new_name) | ... | ... |
... | @@ -365,13 +365,17 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -365,13 +365,17 @@ class Command(BaseCommand, LoggerMixin): |
365 | 365 | ||
366 | def pdf_2_img_2_queue(self, img_queue, todo_count_dict, lock): | 366 | def pdf_2_img_2_queue(self, img_queue, todo_count_dict, lock): |
367 | while self.switch: | 367 | while self.switch: |
368 | try: | ||
368 | # 1. 从队列获取文件信息 | 369 | # 1. 从队列获取文件信息 |
369 | doc, business_type, task_str = self.get_doc_info() | 370 | doc, business_type, task_str = self.get_doc_info() |
370 | # 队列为空时的处理 | 371 | # 队列为空时的处理 |
371 | if doc is None: | 372 | if doc is None: |
372 | time.sleep(self.sleep_time_doc_get) | 373 | time.sleep(self.sleep_time_doc_get) |
373 | continue | 374 | continue |
374 | 375 | except Exception as e: | |
376 | self.cronjob_log.error('{0} [process failed (get doc into)] [error={1}]'.format( | ||
377 | self.log_base, traceback.format_exc())) | ||
378 | else: | ||
375 | try: | 379 | try: |
376 | # 2. 从EDMS获取PDF文件 | 380 | # 2. 从EDMS获取PDF文件 |
377 | doc_data_path = os.path.join(self.data_dir, business_type, consts.TMP_DIR_NAME, str(doc.id)) | 381 | 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): | ... | @@ -418,6 +422,9 @@ class Command(BaseCommand, LoggerMixin): |
418 | continue | 422 | continue |
419 | else: | 423 | else: |
420 | self.cronjob_log.info('{0} [img_2_ocr_1] [get img] [img_path={1}]'.format(self.log_base, img_path)) | 424 | self.cronjob_log.info('{0} [img_2_ocr_1] [get img] [img_path={1}]'.format(self.log_base, img_path)) |
425 | |||
426 | for times in range(consts.RETRY_TIMES): | ||
427 | try: | ||
421 | with open(img_path, 'rb') as f: | 428 | with open(img_path, 'rb') as f: |
422 | base64_data = base64.b64encode(f.read()) | 429 | base64_data = base64.b64encode(f.read()) |
423 | # 获取解码后的base64值 | 430 | # 获取解码后的base64值 |
... | @@ -426,8 +433,6 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -426,8 +433,6 @@ class Command(BaseCommand, LoggerMixin): |
426 | "file": file_data | 433 | "file": file_data |
427 | } | 434 | } |
428 | 435 | ||
429 | for times in range(consts.RETRY_TIMES): | ||
430 | try: | ||
431 | start_time = time.time() | 436 | start_time = time.time() |
432 | ocr_1_response = requests.post(url, json=json_data_1) | 437 | ocr_1_response = requests.post(url, json=json_data_1) |
433 | if ocr_1_response.status_code != 200: | 438 | if ocr_1_response.status_code != 200: |
... | @@ -447,6 +452,7 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -447,6 +452,7 @@ class Command(BaseCommand, LoggerMixin): |
447 | self.cronjob_log.warn('{0} [ocr_1 failed] [img_path={1}]'.format(self.log_base, img_path)) | 452 | self.cronjob_log.warn('{0} [ocr_1 failed] [img_path={1}]'.format(self.log_base, img_path)) |
448 | # continue | 453 | # continue |
449 | 454 | ||
455 | try: | ||
450 | del json_data_1 | 456 | del json_data_1 |
451 | # /data/bmw-ocr-data/AFC/tmp/6/img/page_0_img_0.jpeg | 457 | # /data/bmw-ocr-data/AFC/tmp/6/img/page_0_img_0.jpeg |
452 | # AFC_2 | 458 | # AFC_2 |
... | @@ -463,6 +469,9 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -463,6 +469,9 @@ class Command(BaseCommand, LoggerMixin): |
463 | del todo_count_dict[task_str] | 469 | del todo_count_dict[task_str] |
464 | else: | 470 | else: |
465 | todo_count_dict[task_str] = todo_count - 1 | 471 | todo_count_dict[task_str] = todo_count - 1 |
472 | except Exception as e: | ||
473 | self.cronjob_log.error('{0} [process failed (store ocr res)] [img_path={1}] [error={2}]'.format( | ||
474 | self.log_base, img_path, traceback.format_exc())) | ||
466 | 475 | ||
467 | def res_2_wb(self, res_dict, finish_queue, lock): | 476 | def res_2_wb(self, res_dict, finish_queue, lock): |
468 | while True: | 477 | while True: | ... | ... |
-
Please register or sign in to post a comment