trust_api.services.task_poller
Background polling service that periodically fetches tasks from the central hub and dispatches them to local handlers.
This replaces the previous model where the hub made inbound HTTP requests to the trust. Now all communication is outbound from the trust to the hub.
Attributes
Functions
|
Return authentication headers for hub API calls. |
|
Poll the central hub for pending tasks. |
|
Send a heartbeat to the central hub to indicate this trust is online. |
|
Report the result of a completed task back to the central hub. |
|
Process a single task by dispatching to the appropriate handler. |
|
Main polling loop. Runs indefinitely, polling the hub for tasks and processing them. |
Module Contents
- trust_api.services.task_poller.CENTRAL_HUB_API_URL
- trust_api.services.task_poller.TRUST_API_KEY
- trust_api.services.task_poller.TRUST_API_KEY_HEADER
- trust_api.services.task_poller.TRUST_NAME
- trust_api.services.task_poller.POLL_INTERVAL_SECONDS = 5
- trust_api.services.task_poller._auth_headers() dict[str, str]
Return authentication headers for hub API calls.
- Returns:
Single-entry mapping of the trust API key header to the configured key.
- Return type:
dict[str, str]
- async trust_api.services.task_poller._poll_for_tasks(client: httpx.AsyncClient) list[dict]
Poll the central hub for pending tasks.
- Parameters:
client – HTTP client for making requests.
- Returns:
List of pending task dicts from the hub.
- async trust_api.services.task_poller._send_heartbeat(client: httpx.AsyncClient) None
Send a heartbeat to the central hub to indicate this trust is online.
- Parameters:
client – HTTP client for making requests.
- trust_api.services.task_poller._REPORT_MAX_RETRIES = 3
- trust_api.services.task_poller._REPORT_RETRY_DELAY_SECONDS = 2
- async trust_api.services.task_poller._report_task_result(client: httpx.AsyncClient, task_id: str, result: dict) None
Report the result of a completed task back to the central hub.
Retries up to
_REPORT_MAX_RETRIEStimes with exponential backoff on failure, since a lost result can leave a task permanently stuck in IN_PROGRESS on the hub.- Parameters:
client – HTTP client for making requests.
task_id – The ID of the completed task.
result – The result dict containing success status and optional result data.
- async trust_api.services.task_poller._process_task(task: dict) dict
Process a single task by dispatching to the appropriate handler.
- Parameters:
task – Task dict with id, task_type, and payload fields.
- Returns:
Result dict with success status.
- async trust_api.services.task_poller.run_poller() None
Main polling loop. Runs indefinitely, polling the hub for tasks and processing them.
This function is started as a background task during the FastAPI lifespan.