Skip to content

Commit a6a86a2

Browse files
committed
refactor
1 parent 821aa5c commit a6a86a2

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from models_library.projects_access import Owner
1212
from models_library.projects_state import ProjectLocked, ProjectStatus
1313
from redis.asyncio.lock import Lock
14+
from servicelib.redis._client import RedisClientSDK
1415

1516
from .background_task import periodic_task
1617
from .logging_utils import log_context
@@ -31,7 +32,8 @@ async def _auto_extend_project_lock(project_lock: Lock) -> None:
3132

3233
@asynccontextmanager
3334
async def lock_project(
34-
redis_lock: Lock,
35+
redis_client: RedisClientSDK,
36+
*,
3537
project_uuid: str | ProjectID,
3638
status: ProjectStatus,
3739
owner: Owner | None = None,
@@ -42,6 +44,11 @@ async def lock_project(
4244
ProjectLockError: if project is already locked
4345
"""
4446

47+
redis_lock = redis_client.create_lock(
48+
PROJECT_REDIS_LOCK_KEY.format(project_uuid),
49+
ttl=PROJECT_LOCK_TIMEOUT,
50+
)
51+
4552
try:
4653
if not await redis_lock.acquire(
4754
blocking=False,

services/efs-guardian/src/simcore_service_efs_guardian/services/background_tasks.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
from models_library.projects import ProjectID
66
from models_library.projects_state import ProjectStatus
77
from servicelib.logging_utils import log_context
8-
from servicelib.project_lock import (
9-
PROJECT_LOCK_TIMEOUT,
10-
PROJECT_REDIS_LOCK_KEY,
11-
lock_project,
12-
)
8+
from servicelib.project_lock import lock_project
139
from simcore_postgres_database.utils_projects import (
1410
DBProjectNotFoundError,
1511
ProjectsRepo,
@@ -60,12 +56,8 @@ async def removal_policy_task(app: FastAPI) -> None:
6056
logging.INFO,
6157
msg=f"Removing data for project {project_id} started, project last change date {_project_last_change_date}, efs removal policy task age limit timedelta {app_settings.EFS_REMOVAL_POLICY_TASK_AGE_LIMIT_TIMEDELTA}",
6258
):
63-
redis_lock = get_redis_lock_client(app).create_lock(
64-
PROJECT_REDIS_LOCK_KEY.format(project_id),
65-
ttl=PROJECT_LOCK_TIMEOUT,
66-
)
6759
async with lock_project(
68-
redis_lock,
60+
get_redis_lock_client(app),
6961
project_uuid=project_id,
7062
status=ProjectStatus.MAINTAINING,
7163
):

services/web/server/src/simcore_service_webserver/projects/lock.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
from models_library.projects import ProjectID
77
from models_library.projects_access import Owner
88
from models_library.projects_state import ProjectLocked, ProjectStatus
9-
from servicelib.project_lock import PROJECT_LOCK_TIMEOUT, PROJECT_REDIS_LOCK_KEY
9+
from servicelib.project_lock import PROJECT_REDIS_LOCK_KEY
1010
from servicelib.project_lock import lock_project as common_lock_project
1111

12-
from ..redis import get_redis_lock_manager_client
12+
from ..redis import get_redis_lock_manager_client, get_redis_lock_manager_client_sdk
1313
from ..users.api import FullNameDict
1414

1515
_logger = logging.getLogger(__name__)
@@ -28,15 +28,11 @@ async def lock_project(
2828
Raises:
2929
ProjectLockError: if project is already locked
3030
"""
31-
32-
redis_lock = get_redis_lock_manager_client(app).lock(
33-
PROJECT_REDIS_LOCK_KEY.format(project_uuid),
34-
timeout=PROJECT_LOCK_TIMEOUT.total_seconds(),
35-
)
36-
owner = Owner(user_id=user_id, **user_fullname)
37-
3831
async with common_lock_project(
39-
redis_lock, project_uuid=project_uuid, status=status, owner=owner
32+
get_redis_lock_manager_client_sdk(app),
33+
project_uuid=project_uuid,
34+
status=status,
35+
owner=Owner(user_id=user_id, **user_fullname),
4036
):
4137
yield
4238

0 commit comments

Comments
 (0)