Skip to content

Commit ed8f92c

Browse files
fix
1 parent c76cbd3 commit ed8f92c

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44

55
from celery import Task
6-
from common_library.errors_classes import OsparcErrorMixin
76
from models_library.progress_bar import ProgressReport
87
from models_library.projects_nodes_io import StorageFileID
98
from servicelib.logging_utils import log_context
@@ -29,12 +28,3 @@ def export_data(task: Task, files: list[StorageFileID]):
2928
)
3029
time.sleep(10)
3130
return "done"
32-
33-
34-
class MyError(OsparcErrorMixin, Exception):
35-
msg_template = "Something strange happened: {msg}"
36-
37-
38-
def export_data_with_error(task: Task, files: list[StorageFileID]):
39-
msg = "BOOM!"
40-
raise MyError(msg=msg)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from ...core.settings import ApplicationSettings
1313
from ._common import create_app as create_celery_app, define_task
14-
from .tasks import export_data, export_data_with_error
14+
from .tasks import export_data
1515

1616
_settings = ApplicationSettings.create_from_envs()
1717

@@ -31,4 +31,3 @@
3131
worker_shutdown.connect(on_worker_shutdown)
3232

3333
define_task(app, export_data)
34-
define_task(app, export_data_with_error)

services/storage/tests/unit/modules/celery/test_celery.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pytest
99
from celery import Celery, Task
1010
from celery.contrib.abortable import AbortableTask
11+
from common_library.errors_classes import OsparcErrorMixin
1112
from models_library.progress_bar import ProgressReport
1213
from servicelib.logging_utils import log_context
1314
from simcore_service_storage.modules.celery import get_event_loop
@@ -52,9 +53,13 @@ def sync_archive(task: Task, files: list[str]) -> str:
5253
).result()
5354

5455

55-
def failure_task(task: Task) -> str:
56-
msg = "my error here"
57-
raise ValueError(msg)
56+
class MyError(OsparcErrorMixin, Exception):
57+
msg_template = "Something strange happened: {msg}"
58+
59+
60+
def failure_task(task: Task):
61+
msg = "BOOM!"
62+
raise MyError(msg=msg)
5863

5964

6065
def dreamer_task(task: AbortableTask) -> list[int]:
@@ -130,7 +135,7 @@ async def test_submitting_task_with_failure_results_with_error(
130135
).task_state == TaskState.ERROR
131136
raw_result = await celery_client.get_task_result(task_context, task_uuid)
132137
result = TypeAdapter(TaskError).validate_python(raw_result)
133-
assert f"{result.exc_msg}" == "my error here"
138+
assert f"{result.exc_msg}" == "Something strange happened: BOOM!"
134139

135140

136141
@pytest.mark.usefixtures("celery_worker")

0 commit comments

Comments
 (0)