Skip to content

Commit 0ad38e2

Browse files
committed
refactor: improve document status update logic and enhance post handler functionality
1 parent b71a854 commit 0ad38e2

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

apps/common/event/__init__.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,32 @@
66
@date:2023/11/10 10:43
77
@desc:
88
"""
9-
from models_provider.models import Model, Status
10-
from .listener_manage import *
119
from django.utils.translation import gettext as _
1210

13-
from ..db.sql_execute import update_execute
1411
from common.lock.impl.file_lock import FileLock
12+
from .listener_manage import *
13+
from ..db.sql_execute import update_execute
1514

1615
lock = FileLock()
1716
update_document_status_sql = """
18-
UPDATE "public"."document"
19-
SET status ="replace"("replace"("replace"(status, '1', '3'), '0', '3'), '4', '3')
20-
WHERE status ~ '1|0|4'
21-
"""
17+
UPDATE "public"."document"
18+
SET status ="replace"("replace"("replace"(status, '1', '3'), '0', '3'), '4', '3')
19+
WHERE status ~ '1|0|4' \
20+
"""
2221

2322

2423
def run():
24+
from models_provider.models import Model, Status
25+
2526
if lock.try_lock('event_init', 30 * 30):
2627
try:
27-
QuerySet(Model).filter(status=Status.DOWNLOAD).update(status=Status.ERROR, meta={'message': _( 'The download process was interrupted, please try again')})
28+
# 修改Model状态为ERROR
29+
QuerySet(Model).filter(
30+
status=Status.DOWNLOAD
31+
).update(
32+
status=Status.ERROR, meta={'message': _('The download process was interrupted, please try again')}
33+
)
34+
# 更新文档状态
2835
update_execute(update_document_status_sql, [])
2936
finally:
3037
lock.un_lock('event_init')

apps/maxkb/wsgi.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,16 @@
1414
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'maxkb.settings')
1515

1616
application = get_wsgi_application()
17+
18+
19+
20+
def post_handler():
21+
from common.database_model_manage.database_model_manage import DatabaseModelManage
22+
from common import job
23+
from common import event
24+
25+
event.run()
26+
job.run()
27+
DatabaseModelManage.init()
28+
29+
post_handler()

0 commit comments

Comments
 (0)