Skip to content

Commit dbcbce6

Browse files
author
Andrei Neagu
committed
revert accidentally removed code
1 parent 975e587 commit dbcbce6

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

packages/service-library/src/servicelib/long_running_tasks/http_endpoint_responses.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Any
22

3+
from .errors import TaskNotCompletedError, TaskNotFoundError
34
from .models import TaskBase, TaskId, TaskStatus
45
from .task import TaskContext, TasksManager, TrackedTask
56

@@ -25,14 +26,21 @@ async def get_task_result(
2526
tasks_manager: TasksManager, task_context: TaskContext | None, task_id: TaskId
2627
) -> Any:
2728
try:
28-
return tasks_manager.get_task_result(
29-
task_id=task_id, with_task_context=task_context
29+
task_result = tasks_manager.get_task_result(
30+
task_id, with_task_context=task_context
3031
)
31-
finally:
32-
# the task is always removed even if an error occurs
3332
await tasks_manager.remove_task(
3433
task_id, with_task_context=task_context, reraise_errors=False
3534
)
35+
return task_result
36+
except (TaskNotFoundError, TaskNotCompletedError):
37+
raise
38+
except Exception:
39+
# the task shall be removed in this case
40+
await tasks_manager.remove_task(
41+
task_id, with_task_context=task_context, reraise_errors=False
42+
)
43+
raise
3644

3745

3846
async def remove_task(

0 commit comments

Comments
 (0)