task_utils
task_utils
¶
Shared utilities for asyncio.Task lifecycle in the daemon.
Provides log_task_exception to extract and log exceptions from
completed tasks — used by done-callbacks across the daemon to avoid
silently losing errors from background tasks.
Functions¶
log_task_exception
¶
Extract and log an exception from a completed task.
Call this at the top of any add_done_callback handler to
consistently surface exceptions from background tasks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Task[Any]
|
The completed task to inspect. |
required |
logger
|
Any
|
A structlog or stdlib logger with |
required |
event
|
str
|
Structlog-style event name (e.g. |
required |
level
|
str
|
Log method name — |
'error'
|
Returns:
| Type | Description |
|---|---|
BaseException | None
|
The exception if one was found, |
BaseException | None
|
normally or was cancelled. |