mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
refactor: update locking mechanism to use a consistent key format and set default timeout
This commit is contained in:
parent
0ad38e2540
commit
6068530cdd
|
|
@ -253,7 +253,7 @@ class ListenerManagement:
|
|||
"""
|
||||
if state_list is None:
|
||||
state_list = [State.PENDING, State.SUCCESS, State.FAILURE, State.REVOKE, State.REVOKED]
|
||||
if not try_lock('embedding' + str(document_id)):
|
||||
if not try_lock('embedding:' + str(document_id)):
|
||||
return
|
||||
try:
|
||||
def is_the_task_interrupted():
|
||||
|
|
@ -290,7 +290,7 @@ class ListenerManagement:
|
|||
ListenerManagement.post_update_document_status(document_id, TaskType.EMBEDDING)
|
||||
ListenerManagement.get_aggregation_document_status(document_id)()
|
||||
maxkb_logger.info(_('End--->Embedding document: {document_id}').format(document_id=document_id))
|
||||
un_lock('embedding' + str(document_id))
|
||||
un_lock('embedding:' + str(document_id))
|
||||
|
||||
@staticmethod
|
||||
def embedding_by_knowledge(knowledge_id, embedding_model: Embeddings):
|
||||
|
|
|
|||
|
|
@ -20,7 +20,9 @@ def try_lock(key: str, timeout=None):
|
|||
:param timeout 超时时间
|
||||
:return: 是否获取到锁
|
||||
"""
|
||||
return memory_cache.add(key, 'lock', timeout=timedelta(hours=1).total_seconds() if timeout is not None else timeout)
|
||||
if timeout is None:
|
||||
timeout = 3600 # 默认超时时间为3600秒
|
||||
return memory_cache.add(key, 'lock', timeout=timeout)
|
||||
|
||||
|
||||
def un_lock(key: str):
|
||||
|
|
|
|||
Loading…
Reference in New Issue