refactor: improve document status update logic and enhance post handler functionality
This commit is contained in:
parent
b71a854d7c
commit
0ad38e2540
@ -6,25 +6,32 @@
|
|||||||
@date:2023/11/10 10:43
|
@date:2023/11/10 10:43
|
||||||
@desc:
|
@desc:
|
||||||
"""
|
"""
|
||||||
from models_provider.models import Model, Status
|
|
||||||
from .listener_manage import *
|
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
from ..db.sql_execute import update_execute
|
|
||||||
from common.lock.impl.file_lock import FileLock
|
from common.lock.impl.file_lock import FileLock
|
||||||
|
from .listener_manage import *
|
||||||
|
from ..db.sql_execute import update_execute
|
||||||
|
|
||||||
lock = FileLock()
|
lock = FileLock()
|
||||||
update_document_status_sql = """
|
update_document_status_sql = """
|
||||||
UPDATE "public"."document"
|
UPDATE "public"."document"
|
||||||
SET status ="replace"("replace"("replace"(status, '1', '3'), '0', '3'), '4', '3')
|
SET status ="replace"("replace"("replace"(status, '1', '3'), '0', '3'), '4', '3')
|
||||||
WHERE status ~ '1|0|4'
|
WHERE status ~ '1|0|4' \
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
|
from models_provider.models import Model, Status
|
||||||
|
|
||||||
if lock.try_lock('event_init', 30 * 30):
|
if lock.try_lock('event_init', 30 * 30):
|
||||||
try:
|
try:
|
||||||
QuerySet(Model).filter(status=Status.DOWNLOAD).update(status=Status.ERROR, meta={'message': _( 'The download process was interrupted, please try again')})
|
# 修改Model状态为ERROR
|
||||||
|
QuerySet(Model).filter(
|
||||||
|
status=Status.DOWNLOAD
|
||||||
|
).update(
|
||||||
|
status=Status.ERROR, meta={'message': _('The download process was interrupted, please try again')}
|
||||||
|
)
|
||||||
|
# 更新文档状态
|
||||||
update_execute(update_document_status_sql, [])
|
update_execute(update_document_status_sql, [])
|
||||||
finally:
|
finally:
|
||||||
lock.un_lock('event_init')
|
lock.un_lock('event_init')
|
||||||
|
|||||||
@ -14,3 +14,16 @@ from django.core.wsgi import get_wsgi_application
|
|||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'maxkb.settings')
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'maxkb.settings')
|
||||||
|
|
||||||
application = get_wsgi_application()
|
application = get_wsgi_application()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def post_handler():
|
||||||
|
from common.database_model_manage.database_model_manage import DatabaseModelManage
|
||||||
|
from common import job
|
||||||
|
from common import event
|
||||||
|
|
||||||
|
event.run()
|
||||||
|
job.run()
|
||||||
|
DatabaseModelManage.init()
|
||||||
|
|
||||||
|
post_handler()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user