From e8369f7c4fefe7115fc5038fa233879ac776375b Mon Sep 17 00:00:00 2001 From: Wang Guan Date: Sun, 3 Mar 2024 23:35:42 +0900 Subject: [PATCH] remove CELERY_ABOUT_TO_SHUTDOWN_FLAG --- app/__init__.py | 29 ----------------------------- app/tasks/ocr.py | 6 +++--- 2 files changed, 3 insertions(+), 32 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index ab5ff75..6ea9e53 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,7 +1,6 @@ import os from celery import Celery -from celery.signals import worker_shutting_down from flask import Flask, g, request from flask_apikit import APIKit from flask_babel import Babel @@ -118,18 +117,7 @@ def create_app(): return app -CELERY_ABOUT_TO_SHUTDOWN_FLAG = "CELERY_ABOUT_TO_SHUTDOWN_FLAG" - - -def delete_about_to_shutdown_flag(): - try: - os.rmdir(CELERY_ABOUT_TO_SHUTDOWN_FLAG) - except Exception: - pass - - def create_celery() -> Celery: - delete_about_to_shutdown_flag() # 为celery创建app app = Flask(__name__) app.config.from_envvar( @@ -166,23 +154,6 @@ def create_celery() -> Celery: celery = create_celery() -def create_about_to_shutdown_flag(): - try: - os.mkdir(CELERY_ABOUT_TO_SHUTDOWN_FLAG) - except Exception: - pass - - -@worker_shutting_down.connect -def when_shutdown(**kwargs): - create_about_to_shutdown_flag() - - -def about_to_shutdown(): - """检测 Celery 是否将要关闭""" - return os.path.isdir(CELERY_ABOUT_TO_SHUTDOWN_FLAG) - - @babel.localeselector def get_locale(): current_user = g.get("current_user") diff --git a/app/tasks/ocr.py b/app/tasks/ocr.py index b331728..27f015e 100644 --- a/app/tasks/ocr.py +++ b/app/tasks/ocr.py @@ -8,7 +8,7 @@ from uuid import uuid4 import requests -from app import celery, gs_vision, oss, about_to_shutdown +from app import celery, gs_vision, oss from app.constants.file import FileType, ImageOCRPercent, ParseErrorType, ParseStatus from app.models import connect_db from app.tasks import SyncResult @@ -416,6 +416,8 @@ def inc(self, id, error_name, step=1): def merge_and_ocr(parsing_images, /, *, parse_alone=False): + if 2 > 1: + raise NotImplementedError("OCR under reconstruction") if not parsing_images: return oss_file_prefix = celery.conf.app_config["OSS_FILE_PREFIX"] @@ -532,8 +534,6 @@ def merge_and_ocr(parsing_images, /, *, parse_alone=False): parse_error_type=ParseErrorType.IMAGE_OCR_SERVER_DISCONNECT, ) continue - if about_to_shutdown() is True: - raise AboutToShutdownError for image_data in merged_images_data: image = image_data["image"] image.update(image_ocr_percent=ImageOCRPercent.LABELING)