Skip to content

Commit cb00c7c

Browse files
committed
fix error model
1 parent 514bfa6 commit cb00c7c

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

packages/celery-library/src/celery_library/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ class TaskSubmissionError(OsparcErrorMixin, Exception):
3131

3232

3333
class TaskNotFoundError(OsparcErrorMixin, Exception):
34-
msg_template = "Task with key '{task_key}' was not found"
34+
msg_template = "Task with uuid '{task_uuid}' and owner_metadata '{owner_metadata}' was not found"

packages/celery-library/src/celery_library/task_manager.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ async def cancel_task(
9595
):
9696
task_key = owner_metadata.model_dump_task_key(task_uuid=task_uuid)
9797
if not await self.task_exists(task_key):
98-
raise TaskNotFoundError(task_key=task_key)
98+
raise TaskNotFoundError(
99+
task_uuid=task_uuid, owner_metadata=owner_metadata
100+
)
99101

100102
await self._task_info_store.remove_task(task_key)
101103
await self._forget_task(task_key)
@@ -117,7 +119,9 @@ async def get_task_result(
117119
):
118120
task_key = owner_metadata.model_dump_task_key(task_uuid=task_uuid)
119121
if not await self.task_exists(task_key):
120-
raise TaskNotFoundError(task_key=task_key)
122+
raise TaskNotFoundError(
123+
task_uuid=task_uuid, owner_metadata=owner_metadata
124+
)
121125

122126
async_result = self._celery_app.AsyncResult(task_key)
123127
result = async_result.result
@@ -160,7 +164,9 @@ async def get_task_status(
160164
):
161165
task_key = owner_metadata.model_dump_task_key(task_uuid=task_uuid)
162166
if not await self.task_exists(task_key):
163-
raise TaskNotFoundError(task_key=task_key)
167+
raise TaskNotFoundError(
168+
task_uuid=task_uuid, owner_metadata=owner_metadata
169+
)
164170

165171
task_state = await self._get_task_celery_state(task_key)
166172
return TaskStatus(

services/api-server/tests/unit/service/test_service_function_jobs_task_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# pylint: disable=redefined-outer-name
22

3+
import json
34
from collections.abc import Callable
45

56
import pytest
@@ -51,7 +52,11 @@ async def _raise(*args, **kwargs):
5152
)
5253
for state in list(TaskState)
5354
]
54-
+ [TaskNotFoundError(task_key=_faker.uuid4())],
55+
+ [
56+
TaskNotFoundError(
57+
task_uuid=_faker.uuid4(), owner_metadata=json.dumps({"owner": "test-owner"})
58+
)
59+
],
5560
)
5661
@pytest.mark.parametrize("job_creation_task_id", [_faker.uuid4(), None])
5762
async def test_celery_status_conversion(

0 commit comments

Comments
 (0)