ADD:lock
Showing
1 changed file
with
27 additions
and
25 deletions
... | @@ -10,6 +10,7 @@ import traceback | ... | @@ -10,6 +10,7 @@ import traceback |
10 | from collections import Counter | 10 | from collections import Counter |
11 | from datetime import datetime, date | 11 | from datetime import datetime, date |
12 | from django import db | 12 | from django import db |
13 | from django.db import transaction | ||
13 | from django.utils import timezone | 14 | from django.utils import timezone |
14 | from django.core.management import BaseCommand | 15 | from django.core.management import BaseCommand |
15 | from multiprocessing import Process, Queue, Manager, Lock | 16 | from multiprocessing import Process, Queue, Manager, Lock |
... | @@ -2034,31 +2035,32 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -2034,31 +2035,32 @@ class Command(BaseCommand, LoggerMixin): |
2034 | result_class = HILOCRResult if is_ca else HILSEOCRResult | 2035 | result_class = HILOCRResult if is_ca else HILSEOCRResult |
2035 | else: | 2036 | else: |
2036 | result_class = AFCOCRResult if is_ca else AFCSEOCRResult | 2037 | result_class = AFCOCRResult if is_ca else AFCSEOCRResult |
2037 | res_obj = result_class.objects.filter(application_id=doc.application_id).first() | 2038 | res_obj = result_class.objects.select_for_update().filter(application_id=doc.application_id).first() |
2038 | if res_obj is None: | 2039 | with transaction.atomic(): |
2039 | res_obj = result_class() | 2040 | if res_obj is None: |
2040 | res_obj.application_id = doc.application_id | 2041 | res_obj = result_class() |
2041 | for classify, field in consts.RESULT_MAPPING.items(): | 2042 | res_obj.application_id = doc.application_id |
2042 | if not hasattr(res_obj, field): | 2043 | for classify, field in consts.RESULT_MAPPING.items(): |
2043 | continue | 2044 | if not hasattr(res_obj, field): |
2044 | license_list = license_summary.get(classify) | 2045 | continue |
2045 | if not license_list: | 2046 | license_list = license_summary.get(classify) |
2046 | continue | 2047 | if not license_list: |
2047 | if classify == consts.IC_CLASSIFY and ic_merge: | 2048 | continue |
2048 | license_list[0].update(license_list[1]) | 2049 | if classify == consts.IC_CLASSIFY and ic_merge: |
2049 | license_list.pop(1) | 2050 | license_list[0].update(license_list[1]) |
2050 | elif classify == consts.RP_CLASSIFY and rp_merge: | 2051 | license_list.pop(1) |
2051 | license_list[0].update(license_list[1]) | 2052 | elif classify == consts.RP_CLASSIFY and rp_merge: |
2052 | license_list.pop(1) | 2053 | license_list[0].update(license_list[1]) |
2053 | old_res_str = getattr(res_obj, field) | 2054 | license_list.pop(1) |
2054 | if old_res_str is None: | 2055 | old_res_str = getattr(res_obj, field) |
2055 | last_res_str = json.dumps(license_list) | 2056 | if old_res_str is None: |
2056 | else: | 2057 | last_res_str = json.dumps(license_list) |
2057 | old_res_list = json.loads(old_res_str) | 2058 | else: |
2058 | old_res_list.extend(license_list) | 2059 | old_res_list = json.loads(old_res_str) |
2059 | last_res_str = json.dumps(old_res_list) | 2060 | old_res_list.extend(license_list) |
2060 | setattr(res_obj, field, last_res_str) | 2061 | last_res_str = json.dumps(old_res_list) |
2061 | res_obj.save() | 2062 | setattr(res_obj, field, last_res_str) |
2063 | res_obj.save() | ||
2062 | except Exception as e: | 2064 | except Exception as e: |
2063 | self.online_log.error( | 2065 | self.online_log.error( |
2064 | '{0} [process error (ocr result save)] [task={1}] [error={2}]'.format( | 2066 | '{0} [process error (ocr result save)] [task={1}] [error={2}]'.format( | ... | ... |
-
Please register or sign in to post a comment