Skip to content

Commit e1b66d2

Browse files
author
Andrei Neagu
committed
refactor export data progress
1 parent 434e3aa commit e1b66d2

File tree

5 files changed

+28
-69
lines changed

5 files changed

+28
-69
lines changed

services/storage/src/simcore_service_storage/api/_worker_tasks/_simcore_s3.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from ...modules.celery.models import TaskID, TaskId
1818
from ...modules.celery.utils import get_celery_worker, get_fastapi_app
1919
from ...simcore_s3_dsm import SimcoreS3DataManager
20-
from ...utils.progress_utils import get_tqdm_progress, set_tqdm_absolute_progress
2120

2221
_logger = logging.getLogger(__name__)
2322

@@ -69,34 +68,35 @@ async def export_data(
6968
user_id: UserID,
7069
paths_to_export: list[S3ObjectKey],
7170
) -> StorageFileID:
72-
_logger.info("Exporting (for user='%s') selection: %s", user_id, paths_to_export)
73-
74-
dsm = get_dsm_provider(get_fastapi_app(task.app)).get(
75-
SimcoreS3DataManager.get_location_id()
76-
)
77-
assert isinstance(dsm, SimcoreS3DataManager) # nosec
78-
79-
try:
80-
for path_to_export in paths_to_export:
81-
await dsm.can_read_file(user_id=user_id, file_id=path_to_export)
82-
except FileAccessRightError as err:
83-
raise AccessRightError(
84-
user_id=user_id,
85-
file_id=path_to_export,
86-
location_id=SimcoreS3DataManager.get_location_id(),
87-
) from err
71+
with log_context(
72+
_logger,
73+
logging.INFO,
74+
f"'{task_id}' export data (for {user_id=}) fom selection: {paths_to_export}",
75+
):
76+
dsm = get_dsm_provider(get_fastapi_app(task.app)).get(
77+
SimcoreS3DataManager.get_location_id()
78+
)
79+
assert isinstance(dsm, SimcoreS3DataManager) # nosec
8880

89-
with get_tqdm_progress(total=1, description=f"{task.name}") as pbar:
81+
try:
82+
for path_to_export in paths_to_export:
83+
await dsm.can_read_file(user_id=user_id, file_id=path_to_export)
84+
except FileAccessRightError as err:
85+
raise AccessRightError(
86+
user_id=user_id,
87+
file_id=path_to_export,
88+
location_id=SimcoreS3DataManager.get_location_id(),
89+
) from err
9090

9191
async def _progress_cb(report: ProgressReport) -> None:
92-
set_tqdm_absolute_progress(pbar, report)
9392
assert task.name # nosec
94-
await get_celery_worker(task.app).set_task_progress(
95-
task.name, task_id, report
96-
)
93+
get_celery_worker(task.app).set_task_progress(task.name, task_id, report)
94+
_logger.debug("'%s' progress %s", task_id, report.percent_value)
9795

9896
async with ProgressBarData(
99-
num_steps=1, description="data export", progress_report_cb=_progress_cb
97+
num_steps=1,
98+
description=f"'{task_id}' export data",
99+
progress_report_cb=_progress_cb,
100100
) as progress_bar:
101101
return await dsm.create_s3_export(
102102
user_id, paths_to_export, progress_bar=progress_bar

services/storage/src/simcore_service_storage/modules/celery/worker.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import logging
22

33
from celery import Celery # type: ignore[import-untyped]
4-
from common_library.async_tools import make_async
54
from models_library.progress_bar import ProgressReport
65
from servicelib.logging_utils import log_context
76

@@ -14,7 +13,6 @@ class CeleryTaskQueueWorker:
1413
def __init__(self, celery_app: Celery) -> None:
1514
self.celery_app = celery_app
1615

17-
@make_async()
1816
def set_task_progress(
1917
self, task_name: str, task_id: TaskID, report: ProgressReport
2018
) -> None:

services/storage/src/simcore_service_storage/utils/progress_utils.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

services/storage/tests/unit/test_rpc_handlers_simcore_s3.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ async def _request_start_data_export(
514514
rpc_client: RabbitMQRPCClient,
515515
user_id: UserID,
516516
product_name: ProductName,
517-
paths_to_export: list[SimcoreS3FileID],
517+
paths_to_export: list[Path],
518518
*,
519519
client_timeout: datetime.timedelta = datetime.timedelta(seconds=60),
520520
) -> dict[str, Any]:
@@ -601,7 +601,7 @@ async def test_start_data_export(
601601
storage_rabbitmq_rpc_client,
602602
user_id,
603603
product_name,
604-
paths_to_export=list(paths_to_export),
604+
paths_to_export=[Path(x) for x in paths_to_export],
605605
)
606606

607607
assert re.fullmatch(
@@ -628,7 +628,9 @@ async def test_start_data_export_access_error(
628628
storage_rabbitmq_rpc_client,
629629
user_id,
630630
product_name,
631-
paths_to_export=[f"{faker.uuid4()}/{faker.uuid4()}/{faker.file_name()}"],
631+
paths_to_export=[
632+
Path(f"{faker.uuid4()}/{faker.uuid4()}/{faker.file_name()}")
633+
],
632634
client_timeout=datetime.timedelta(seconds=60),
633635
)
634636

services/storage/tests/unit/test_utils_progress_utils.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)