Skip to content

Commit 000a397

Browse files
authored
fix: Multi process startup document modification executed multiple times (#2581)
1 parent be31989 commit 000a397

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

apps/common/event/__init__.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,22 @@
1212
from django.utils.translation import gettext as _
1313

1414
from ..db.sql_execute import update_execute
15+
from common.lock.impl.file_lock import FileLock
1516

17+
lock = FileLock()
1618
update_document_status_sql = """
1719
UPDATE "public"."document"
1820
SET status ="replace"("replace"("replace"(status, '1', '3'), '0', '3'), '4', '3')
21+
WHERE status ~ '1|0|4'
1922
"""
2023

2124

2225
def run():
23-
# QuerySet(Document).filter(status__in=[Status.embedding, Status.queue_up]).update(**{'status': Status.error})
24-
QuerySet(Model).filter(status=setting.models.Status.DOWNLOAD).update(status=setting.models.Status.ERROR,
25-
meta={'message': _('The download process was interrupted, please try again')})
26-
update_execute(update_document_status_sql, [])
26+
if lock.try_lock('event_init', 30 * 30):
27+
try:
28+
QuerySet(Model).filter(status=setting.models.Status.DOWNLOAD).update(status=setting.models.Status.ERROR,
29+
meta={'message': _(
30+
'The download process was interrupted, please try again')})
31+
update_execute(update_document_status_sql, [])
32+
finally:
33+
lock.un_lock('event_init')

0 commit comments

Comments
 (0)