Files
life-echo/api/app/core/chapter_pipeline_lock.py

25 lines
749 B
Python
Raw Permalink Normal View History

"""Pipeline 章节级 Redis 锁:与 memoir pipeline / recompose_chapter 共用同一 key 空间。"""
from app.core.redis_lock import (
RedisLockHandle,
acquire_redis_lock,
release_redis_lock,
)
ChapterPipelineLockHandle = RedisLockHandle
def _lock_key(user_id: str, stage: str) -> str:
return f"lock:chapter:{user_id}:{stage}"
def acquire_chapter_pipeline_lock(
user_id: str, stage: str, *, ttl_seconds: int
) -> ChapterPipelineLockHandle | None:
"""获取 `lock:chapter:{user_id}:{stage}`;失败返回 None。"""
return acquire_redis_lock(_lock_key(user_id, stage), ttl_seconds=ttl_seconds)
def release_chapter_pipeline_lock(handle: ChapterPipelineLockHandle | None) -> None:
release_redis_lock(handle)