symfonic.infra¶
infra ¶
symfonic.infra -- infrastructure abstractions for external services.
Provides protocol interfaces that the library depends on without importing concrete implementations (Celery, APScheduler, etc.).
ExecutionTrace
dataclass
¶
ExecutionTrace(
run_id: str,
source: str = "chat",
start_time: float = time.monotonic(),
events: list[TraceEvent] = list(),
)
InMemoryTraceStore ¶
Default trace store using an in-memory bounded deque.
Suitable for development and single-process deployments. Data is lost on restart. For production, inject a PostgresTraceStore or similar adapter that satisfies TraceStoreProtocol.
Source code in src/symfonic/infra/trace.py
finish_trace ¶
Append a done event and move the trace to completed storage.
Source code in src/symfonic/infra/trace.py
get_trace ¶
latest ¶
start_trace ¶
Create a new active trace and return it.
Source code in src/symfonic/infra/trace.py
NullScheduler ¶
No-op scheduler that silently discards all task requests.
Used as the default when no external scheduler is configured, ensuring the library functions standalone without Celery or any other task infrastructure.
cancel_task
async
¶
enqueue_task
async
¶
Accept and discard the task request.
Source code in src/symfonic/infra/protocols.py
schedule_recurring
async
¶
schedule_recurring(
task_name: str,
interval_seconds: float,
params: dict[str, Any] | None = None,
) -> str
Accept and discard the recurring schedule request.
Source code in src/symfonic/infra/protocols.py
TaskSchedulerProtocol ¶
Bases: Protocol
Abstract interface for background task scheduling.
All methods accept a task_name string that the adapter maps
to a concrete task implementation (e.g. a Celery task, an
APScheduler job, etc.).
cancel_task
async
¶
Cancel a previously enqueued or recurring task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_id
|
str
|
The identifier returned by |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the task was found and cancelled, False otherwise. |
Source code in src/symfonic/infra/protocols.py
enqueue_task
async
¶
Enqueue a task for immediate background execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_name
|
str
|
Identifier for the task to execute. |
required |
params
|
dict[str, Any] | None
|
Optional keyword arguments for the task. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A task ID string that can be used with |
Source code in src/symfonic/infra/protocols.py
schedule_recurring
async
¶
schedule_recurring(
task_name: str,
interval_seconds: float,
params: dict[str, Any] | None = None,
) -> str
Schedule a task to run repeatedly at a fixed interval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_name
|
str
|
Identifier for the task. |
required |
interval_seconds
|
float
|
Seconds between successive executions. |
required |
params
|
dict[str, Any] | None
|
Optional keyword arguments for each invocation. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A task ID string for cancellation. |
Source code in src/symfonic/infra/protocols.py
TraceEvent
dataclass
¶
Single event in an execution trace.
TraceStoreProtocol ¶
Bases: Protocol
Abstract interface for execution trace storage.
All concrete adapters (in-memory, PostgreSQL, Redis, …) must satisfy this structural protocol. The library never imports a concrete class.
finish_trace ¶
Mark a trace as complete and move it from active to storage.
A "done" event is appended before archiving. Calling with an unknown run_id is a no-op.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_id
|
str
|
Identifier of the trace to finish. |
required |
Source code in src/symfonic/infra/trace.py
get_trace ¶
Return an active (in-progress) trace, or None if not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_id
|
str
|
Identifier to look up. |
required |
latest ¶
Return the most recent completed traces as plain dicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
Maximum number of traces to return. |
10
|
start_trace ¶
Begin tracking a new execution trace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_id
|
str
|
Unique identifier for this execution run. |
required |
source
|
str
|
Label for the caller type (e.g. "chat", "stream", "worker"). |
'chat'
|
Returns:
| Type | Description |
|---|---|
ExecutionTrace
|
The newly created ExecutionTrace with an initial "start" event. |