Skip to content

Commit 6068530

Browse files
committed
refactor: update locking mechanism to use a consistent key format and set default timeout
1 parent 0ad38e2 commit 6068530

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

apps/common/event/listener_manage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def embedding_by_document(document_id, embedding_model: Embeddings, state_list=N
253253
"""
254254
if state_list is None:
255255
state_list = [State.PENDING, State.SUCCESS, State.FAILURE, State.REVOKE, State.REVOKED]
256-
if not try_lock('embedding' + str(document_id)):
256+
if not try_lock('embedding:' + str(document_id)):
257257
return
258258
try:
259259
def is_the_task_interrupted():
@@ -290,7 +290,7 @@ def is_the_task_interrupted():
290290
ListenerManagement.post_update_document_status(document_id, TaskType.EMBEDDING)
291291
ListenerManagement.get_aggregation_document_status(document_id)()
292292
maxkb_logger.info(_('End--->Embedding document: {document_id}').format(document_id=document_id))
293-
un_lock('embedding' + str(document_id))
293+
un_lock('embedding:' + str(document_id))
294294

295295
@staticmethod
296296
def embedding_by_knowledge(knowledge_id, embedding_model: Embeddings):

apps/common/utils/lock.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ def try_lock(key: str, timeout=None):
2020
:param timeout 超时时间
2121
:return: 是否获取到锁
2222
"""
23-
return memory_cache.add(key, 'lock', timeout=timedelta(hours=1).total_seconds() if timeout is not None else timeout)
23+
if timeout is None:
24+
timeout = 3600 # 默认超时时间为3600秒
25+
return memory_cache.add(key, 'lock', timeout=timeout)
2426

2527

2628
def un_lock(key: str):

0 commit comments

Comments
 (0)