flip_api.private_services.trust_tasks

Attributes

router

PENDING_TASKS_LIMIT

Functions

_get_trust_by_name(→ flip_api.db.models.main_models.Trust)

Look up a trust by name, raising 404 if not found.

get_pending_tasks(, authenticated_trust)

Returns pending tasks for the specified trust and marks them as in_progress.

submit_task_result(, db, authenticated_trust, str])

Receives the result of a completed task from a trust.

trust_heartbeat(, authenticated_trust, str])

Receives a heartbeat from a trust, updating its last_heartbeat timestamp.

Module Contents

flip_api.private_services.trust_tasks.router
flip_api.private_services.trust_tasks.PENDING_TASKS_LIMIT = 50
flip_api.private_services.trust_tasks._get_trust_by_name(trust_name: str, db: sqlmodel.Session) flip_api.db.models.main_models.Trust

Look up a trust by name, raising 404 if not found.

Parameters:
  • trust_name (str) – Name of the trust to look up.

  • db (Session) – Database session.

Returns:

The trust object.

Return type:

Trust

Raises:

HTTPException – 404 if the trust is not found.

flip_api.private_services.trust_tasks.get_pending_tasks(request: fastapi.Request, trust_name: str, db: sqlmodel.Session = Depends(get_session), authenticated_trust: str = Depends(authenticate_trust)) list[flip_api.domain.schemas.private.TrustTaskResponse]

Returns pending tasks for the specified trust and marks them as in_progress.

This endpoint is polled by trusts to pick up work dispatched by the central hub.

Parameters:
  • request (Request) – The FastAPI request, used by the rate limiter.

  • trust_name (str) – The trust polling for tasks, taken from the URL path.

  • db (Session) – Database session, provided by dependency injection.

  • authenticated_trust (str) – The trust name resolved from the API key, provided by dependency injection.

Returns:

Pending tasks (up to PENDING_TASKS_LIMIT), now marked IN_PROGRESS, with payloads encrypted for transport.

Return type:

list[TrustTaskResponse]

Raises:

HTTPException – 403 if the authenticated trust doesn’t match trust_name, 404 if the trust is not registered, 500 on any other error.

flip_api.private_services.trust_tasks.submit_task_result(request: fastapi.Request, trust_name: str, task_id: uuid.UUID, task_result: flip_api.domain.schemas.private.TaskResultInput = Body(...), db: sqlmodel.Session = Depends(get_session), authenticated_trust: str = Depends(authenticate_trust)) dict[str, str]

Receives the result of a completed task from a trust.

The trust_name path parameter is verified against the authenticated trust identity to prevent one trust from submitting results for another trust’s tasks.

Parameters:
  • request (Request) – The FastAPI request, used by the rate limiter.

  • trust_name (str) – The trust submitting the result, taken from the URL path.

  • task_id (UUID) – The ID of the task whose result is being submitted.

  • task_result (TaskResultInput) – The task outcome reported by the trust.

  • db (Session) – Database session, provided by dependency injection.

  • authenticated_trust (str) – The trust name resolved from the API key, provided by dependency injection.

Returns:

{"message": "Task <id> result recorded"} on success.

Return type:

dict[str, str]

Raises:

HTTPException – 403 if the authenticated trust doesn’t match trust_name or the task belongs to a different trust; 404 if the trust or task is not found; 409 if the task is not currently IN_PROGRESS; 500 on any other error.

flip_api.private_services.trust_tasks.trust_heartbeat(request: fastapi.Request, trust_name: str, db: sqlmodel.Session = Depends(get_session), authenticated_trust: str = Depends(authenticate_trust)) dict[str, str]

Receives a heartbeat from a trust, updating its last_heartbeat timestamp.

This replaces the hub-initiated health check with a trust-initiated heartbeat.

Parameters:
  • request (Request) – The FastAPI request, used by the rate limiter.

  • trust_name (str) – The trust sending the heartbeat, taken from the URL path.

  • db (Session) – Database session, provided by dependency injection.

  • authenticated_trust (str) – The trust name resolved from the API key, provided by dependency injection.

Returns:

{"message": "Heartbeat recorded"} on success.

Return type:

dict[str, str]

Raises:

HTTPException – 403 if the authenticated trust doesn’t match trust_name, 404 if the trust is not registered, 500 on any other error.