Skip to content

Commit 79c8a18

Browse files
committed
1 parent e673301 commit 79c8a18

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import data_manager

packages/simcore-sdk/src/simcore_sdk/node_data/data_manager.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import logging
22
from pathlib import Path
3-
from shutil import make_archive, unpack_archive, move
3+
from shutil import make_archive, move, unpack_archive
44
from tempfile import TemporaryDirectory
5+
from typing import Optional, Union
56

67
from simcore_sdk.node_ports import config, filemanager
78

89
log = logging.getLogger(__name__)
910

10-
def _create_s3_object(file_path: Path) -> str:
11-
return "{}/{}/{}".format(config.PROJECT_ID, config.NODE_UUID, file_path.name)
11+
def _create_s3_object(file_path: Union[Path, str]) -> str:
12+
file_name = file_path.name if isinstance(file_path, Path) else file_path
13+
return f"{config.PROJECT_ID}/{config.NODE_UUID}/{file_name}"
1214

1315

14-
async def _push_file(file_path: Path):
16+
async def _push_file(file_path: Path, rename_to: Optional[str]):
1517
store_id = 0 # this is for simcore.s3
1618
s3_object = _create_s3_object(file_path)
1719
log.info("uploading %s to S3 to %s...", file_path.name, s3_object)
@@ -20,16 +22,16 @@ async def _push_file(file_path: Path):
2022
local_file_path=file_path)
2123
log.info("%s successfuly uploaded", file_path)
2224

23-
async def push(file_or_folder: Path):
25+
async def push(file_or_folder: Path, rename_to: Optional[str] = None):
2426
if file_or_folder.is_file():
25-
return await _push_file(file_or_folder)
27+
return await _push_file(file_or_folder, rename_to)
2628
# we have a folder, so we create a compressed file
2729
with TemporaryDirectory() as tmp_dir_name:
2830
log.info("compressing %s into %s...", file_or_folder.name, tmp_dir_name)
2931
# compress the files
30-
compressed_file_wo_ext = Path(tmp_dir_name) / file_or_folder.stem
32+
compressed_file_wo_ext = Path(tmp_dir_name) / (rename_to if rename_to else file_or_folder.stem)
3133
archive_file = Path(make_archive(str(compressed_file_wo_ext), 'zip', root_dir=file_or_folder)) #, base_dir=folder))
32-
return await _push_file(archive_file)
34+
return await _push_file(archive_file, rename_to)
3335

3436
async def _pull_file(file_path: Path):
3537
s3_object = _create_s3_object(file_path)

services/sidecar/src/sidecar/core.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from celery.utils.log import get_task_logger
1515

1616
import pika
17-
from simcore_sdk import node_ports
17+
from simcore_sdk import node_ports, node_data
1818
from simcore_sdk.models.pipeline_models import (RUNNING, SUCCESS,
1919
ComputationalPipeline,
2020
ComputationalTask)
@@ -276,9 +276,10 @@ def _process_task_log(self):
276276
277277
- put them all into S3 /logg
278278
"""
279-
return
280-
#directory = self._executor.log_dir
281-
#if os.path.exists(directory):
279+
directory = Path(self._executor.log_dir)
280+
281+
if directory.exists():
282+
wrap_async_call(node_data.data_manager.push(directory, rename_to="logs"))
282283
# for root, _dirs, files in os.walk(directory):
283284
# for name in files:
284285
# filepath = os.path.join(root, name)

0 commit comments

Comments
 (0)