Skip to content

Commit 3303ee9

Browse files
committed
backwards compatibility
1 parent 5654d4a commit 3303ee9

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

packages/service-library/src/servicelib/project_lock.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from models_library.projects_access import Owner
1010
from models_library.projects_state import ProjectLocked, ProjectStatus
1111

12-
from .redis import RedisClientSDK, exclusive
12+
from .redis import CouldNotAcquireLockError, RedisClientSDK, exclusive
1313

1414
PROJECT_REDIS_LOCK_KEY: str = "project_lock:{}"
1515
PROJECT_LOCK_TIMEOUT: Final[datetime.timedelta] = datetime.timedelta(seconds=10)
@@ -33,18 +33,24 @@ def with_locked_project(
3333
def _decorator(
3434
func: Callable[P, Coroutine[Any, Any, R]],
3535
) -> Callable[P, Coroutine[Any, Any, R]]:
36-
@exclusive(
37-
redis_client,
38-
lock_key=PROJECT_REDIS_LOCK_KEY.format(project_uuid),
39-
lock_value=ProjectLocked(
40-
value=True,
41-
owner=owner,
42-
status=status,
43-
).model_dump_json(),
44-
)
4536
@functools.wraps(func)
4637
async def _wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
47-
return await func(*args, **kwargs)
38+
@exclusive(
39+
redis_client,
40+
lock_key=PROJECT_REDIS_LOCK_KEY.format(project_uuid),
41+
lock_value=ProjectLocked(
42+
value=True,
43+
owner=owner,
44+
status=status,
45+
).model_dump_json(),
46+
)
47+
async def _exclusive_func(*args, **kwargs) -> R:
48+
return await func(*args, **kwargs)
49+
50+
try:
51+
return await _exclusive_func(*args, **kwargs)
52+
except CouldNotAcquireLockError as e:
53+
raise ProjectLockError from e
4854

4955
return _wrapper
5056

0 commit comments

Comments
 (0)