Skip to content

Commit c2104b5

Browse files
author
Andrei Neagu
committed
task now logs error
1 parent 56d08bc commit c2104b5

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
import logging
2+
import traceback
13
from typing import Any
24

35
from .errors import TaskNotCompletedError, TaskNotFoundError
46
from .models import TaskBase, TaskId, TaskStatus
57
from .task import TaskContext, TasksManager, TrackedTask
68

9+
_logger = logging.getLogger(__name__)
10+
711

812
def list_tasks(
913
tasks_manager: TasksManager, task_context: TaskContext | None
@@ -35,7 +39,11 @@ async def get_task_result(
3539
return task_result
3640
except (TaskNotFoundError, TaskNotCompletedError):
3741
raise
38-
except Exception:
42+
except Exception as exc:
43+
# the task raised an exception
44+
formatted_traceback = "".join(traceback.format_exception(exc))
45+
_logger.info("Task '%s' raised an exception: %s", task_id, formatted_traceback)
46+
3947
# the task shall be removed in this case
4048
await tasks_manager.remove_task(
4149
task_id, with_task_context=task_context, reraise_errors=False

0 commit comments

Comments
 (0)