Skip to content

Commit 15263b7

Browse files
committed
added new exception in case of incorrect usage of inputs
1 parent 60f15e4 commit 15263b7

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

services/dask-sidecar/src/simcore_service_dask_sidecar/computational_sidecar/core.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
from aiodocker import Docker
1414
from common_library.json_serialization import json_dumps
1515
from dask_task_models_library.container_tasks.docker import DockerBasicAuth
16-
from dask_task_models_library.container_tasks.errors import ServiceRuntimeError
16+
from dask_task_models_library.container_tasks.errors import (
17+
ServiceInputsUseFileToKeyMapButReceivesZipDataError,
18+
ServiceRuntimeError,
19+
)
1720
from dask_task_models_library.container_tasks.io import FileUrl, TaskOutputData
1821
from dask_task_models_library.container_tasks.protocol import ContainerTaskParameters
1922
from models_library.progress_bar import ProgressReport
@@ -27,7 +30,11 @@
2730

2831
from ..settings import ApplicationSettings
2932
from ..utils.dask import TaskPublisher
30-
from ..utils.files import pull_file_from_remote, push_file_to_remote
33+
from ..utils.files import (
34+
check_need_unzipping,
35+
pull_file_from_remote,
36+
push_file_to_remote,
37+
)
3138
from .docker_utils import (
3239
create_container_config,
3340
get_computational_shared_data_mount_point,
@@ -75,6 +82,17 @@ async def _write_input_data(
7582

7683
destination_path = task_volumes.inputs_folder / file_name
7784

85+
need_extraction = check_need_unzipping(
86+
input_params.url, input_params.file_mime_type, destination_path
87+
)
88+
if input_params.file_mapping and need_extraction:
89+
raise ServiceInputsUseFileToKeyMapButReceivesZipDataError(
90+
service_key=self.task_parameters.image,
91+
service_version=self.task_parameters.tag,
92+
input_key=input_key,
93+
file_to_key_map=input_params.file_mapping,
94+
)
95+
7896
if destination_path.parent != task_volumes.inputs_folder:
7997
# NOTE: only 'task_volumes.inputs_folder' part of 'destination_path' is guaranteed,
8098
# if extra subfolders via file-mapping,

services/dask-sidecar/src/simcore_service_dask_sidecar/computational_sidecar/task_shared_volume.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import logging
32
import shutil
43
from dataclasses import dataclass
@@ -23,7 +22,7 @@ def __post_init__(self) -> None:
2322

2423
assert not folder_path.exists() # nosec
2524
folder_path.mkdir(parents=True)
26-
logger.debug(
25+
logger.critical(
2726
"created %s in %s",
2827
f"{folder=}",
2928
f"{self.base_path=}",
@@ -61,4 +60,5 @@ async def __aexit__(
6160
exc: BaseException | None,
6261
tb: TracebackType | None,
6362
) -> None:
64-
await asyncio.get_event_loop().run_in_executor(None, self.cleanup)
63+
...
64+
# await asyncio.get_event_loop().run_in_executor(None, self.cleanup)

services/dask-sidecar/src/simcore_service_dask_sidecar/utils/files.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,22 @@ async def _copy_file(
141141
_ZIP_MIME_TYPE: Final[str] = "application/zip"
142142

143143

144+
def check_need_unzipping(
145+
src_url: AnyUrl,
146+
target_mime_type: str | None,
147+
dst_path: Path,
148+
) -> bool:
149+
"""
150+
Checks if the source URL points to a zip file and if the target mime type is not zip.
151+
If so, extraction is needed.
152+
"""
153+
src_mime_type, _ = mimetypes.guess_type(f"{src_url.path}")
154+
dst_mime_type = target_mime_type
155+
if not dst_mime_type:
156+
dst_mime_type, _ = mimetypes.guess_type(dst_path)
157+
return (src_mime_type == _ZIP_MIME_TYPE) and (dst_mime_type != _ZIP_MIME_TYPE)
158+
159+
144160
async def pull_file_from_remote(
145161
src_url: AnyUrl,
146162
target_mime_type: str | None,
@@ -157,17 +173,11 @@ async def pull_file_from_remote(
157173
msg = f"{dst_path.parent=} does not exist. It must be created by the caller"
158174
raise ValueError(msg)
159175

160-
src_mime_type, _ = mimetypes.guess_type(f"{src_url.path}")
161-
if not target_mime_type:
162-
target_mime_type, _ = mimetypes.guess_type(dst_path)
163-
164176
storage_kwargs: S3FsSettingsDict | dict[str, Any] = {}
165177
if s3_settings and src_url.scheme in S3_FILE_SYSTEM_SCHEMES:
166178
storage_kwargs = _s3fs_settings_from_s3_settings(s3_settings)
167179

168-
need_extraction = (src_mime_type == _ZIP_MIME_TYPE) and (
169-
target_mime_type != _ZIP_MIME_TYPE
170-
)
180+
need_extraction = check_need_unzipping(src_url, target_mime_type, dst_path)
171181
async with AsyncExitStack() as exit_stack:
172182
if need_extraction:
173183
# we need to extract the file, so we create a temporary directory

0 commit comments

Comments
 (0)