Skip to content

Commit 5868e41

Browse files
author
Andrei Neagu
committed
refactor
1 parent acb7653 commit 5868e41

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/modules/long_running_tasks.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import functools
22
import logging
3-
import os
43
from collections.abc import AsyncGenerator
54
from contextlib import asynccontextmanager
6-
from datetime import timedelta
75
from pathlib import Path
86
from typing import Final
97

@@ -52,11 +50,13 @@
5250
from ..models.schemas.containers import ContainersCreate
5351
from ..models.shared_store import SharedStore
5452
from ..modules import nodeports, user_services_preferences
55-
from ..modules.container_utils import run_command_in_container
5653
from ..modules.mounted_fs import MountedVolumes
5754
from ..modules.notifications._notifications_ports import PortNotifier
5855
from ..modules.outputs import OutputsManager, event_propagation_disabled
59-
from .long_running_tasks_utils import run_before_shutdown_actions
56+
from .long_running_tasks_utils import (
57+
ensure_read_permissions_on_user_service_data,
58+
run_before_shutdown_actions,
59+
)
6060
from .resource_tracking import send_service_started, send_service_stopped
6161

6262
_logger = logging.getLogger(__name__)
@@ -67,7 +67,6 @@
6767
# NOTE: most services have only 1 "working" directory
6868
CONCURRENCY_STATE_SAVE_RESTORE: Final[int] = 2
6969
_MINUTE: Final[int] = 60
70-
_TIMEOUT_PERMISSION_CHANGES: Final[timedelta] = timedelta(minutes=5)
7170

7271

7372
def _raise_for_errors(
@@ -317,18 +316,7 @@ async def _send_resource_tracking_stop(platform_status: SimcorePlatformStatus):
317316
await _send_resource_tracking_stop(SimcorePlatformStatus.OK)
318317
raise
319318

320-
# make sure sidecar has access to the files and that the user did not accidetally remove read access
321-
# NOTE: command runs inside self container since the user service container might not always be running
322-
self_container = os.environ["HOSTNAME"]
323-
for path_to_store in ( # apply changes to otuputs and all state folders
324-
*mounted_volumes.disk_state_paths_iter(),
325-
mounted_volumes.disk_outputs_path,
326-
):
327-
await run_command_in_container(
328-
self_container,
329-
command=f"chmod -R go+rX {path_to_store}",
330-
timeout=_TIMEOUT_PERMISSION_CHANGES.total_seconds(),
331-
)
319+
await ensure_read_permissions_on_user_service_data(mounted_volumes)
332320

333321
await _send_resource_tracking_stop(SimcorePlatformStatus.OK)
334322

services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/modules/long_running_tasks_utils.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import logging
2+
import os
3+
from datetime import timedelta
4+
from typing import Final
25

36
from models_library.callbacks_mapping import UserServiceCommand
47
from servicelib.logging_utils import log_context
@@ -8,11 +11,14 @@
811
ContainerExecContainerNotFoundError,
912
ContainerExecTimeoutError,
1013
)
14+
from ..core.utils import MountedVolumes
1115
from ..models.shared_store import SharedStore
1216
from .container_utils import run_command_in_container
1317

1418
_logger = logging.getLogger(__name__)
1519

20+
_TIMEOUT_PERMISSION_CHANGES: Final[timedelta] = timedelta(minutes=5)
21+
1622

1723
async def run_before_shutdown_actions(
1824
shared_store: SharedStore, before_shutdown: list[UserServiceCommand]
@@ -40,3 +46,20 @@ async def run_before_shutdown_actions(
4046
container_name,
4147
exc_info=True,
4248
)
49+
50+
51+
async def ensure_read_permissions_on_user_service_data(
52+
mounted_volumes: MountedVolumes,
53+
) -> None:
54+
# make sure sidecar has access to the files and that the user did not accidetally remove read access
55+
# NOTE: command runs inside self container since the user service container might not always be running
56+
self_container = os.environ["HOSTNAME"]
57+
for path_to_store in ( # apply changes to otuputs and all state folders
58+
*mounted_volumes.disk_state_paths_iter(),
59+
mounted_volumes.disk_outputs_path,
60+
):
61+
await run_command_in_container(
62+
self_container,
63+
command=f"chmod -R go+rX {path_to_store}",
64+
timeout=_TIMEOUT_PERMISSION_CHANGES.total_seconds(),
65+
)

0 commit comments

Comments
 (0)