flip_api.private_services.trust_tasks ===================================== .. py:module:: flip_api.private_services.trust_tasks Attributes ---------- .. autoapisummary:: flip_api.private_services.trust_tasks.router flip_api.private_services.trust_tasks.PENDING_TASKS_LIMIT Functions --------- .. autoapisummary:: flip_api.private_services.trust_tasks._get_trust_by_name flip_api.private_services.trust_tasks.get_pending_tasks flip_api.private_services.trust_tasks.submit_task_result flip_api.private_services.trust_tasks.trust_heartbeat Module Contents --------------- .. py:data:: router .. py:data:: PENDING_TASKS_LIMIT :value: 50 .. py:function:: _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. :param trust_name: Name of the trust to look up. :type trust_name: str :param db: Database session. :type db: Session :returns: The trust object. :rtype: Trust :raises HTTPException: 404 if the trust is not found. .. py:function:: 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. :param request: The FastAPI request, used by the rate limiter. :type request: Request :param trust_name: The trust polling for tasks, taken from the URL path. :type trust_name: str :param db: Database session, provided by dependency injection. :type db: Session :param authenticated_trust: The trust name resolved from the API key, provided by dependency injection. :type authenticated_trust: str :returns: Pending tasks (up to ``PENDING_TASKS_LIMIT``), now marked ``IN_PROGRESS``, with payloads encrypted for transport. :rtype: 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. .. py:function:: 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. :param request: The FastAPI request, used by the rate limiter. :type request: Request :param trust_name: The trust submitting the result, taken from the URL path. :type trust_name: str :param task_id: The ID of the task whose result is being submitted. :type task_id: UUID :param task_result: The task outcome reported by the trust. :type task_result: TaskResultInput :param db: Database session, provided by dependency injection. :type db: Session :param authenticated_trust: The trust name resolved from the API key, provided by dependency injection. :type authenticated_trust: str :returns: ``{"message": "Task result recorded"}`` on success. :rtype: 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. .. py:function:: 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. :param request: The FastAPI request, used by the rate limiter. :type request: Request :param trust_name: The trust sending the heartbeat, taken from the URL path. :type trust_name: str :param db: Database session, provided by dependency injection. :type db: Session :param authenticated_trust: The trust name resolved from the API key, provided by dependency injection. :type authenticated_trust: str :returns: ``{"message": "Heartbeat recorded"}`` on success. :rtype: 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.