File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
packages/service-library/src/servicelib/long_running_tasks Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change 11from typing import Any
22
3+ from .errors import TaskNotCompletedError , TaskNotFoundError
34from .models import TaskBase , TaskId , TaskStatus
45from .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
3846async def remove_task (
You can’t perform that action at this time.
0 commit comments