feat(api): GET /deckies/lifecycle + master startup sweep
GET /deckies/lifecycle?ids=<uuid>&ids=<uuid> returns the matching DeckyLifecycle rows so the wizard can poll instead of holding an HTTP request open across compose work. require_viewer gating -- read-only. Startup sweep: on master boot, any pending/running row with started_at older than 1h flips to failed with error='master restarted during operation'. Pre-v1 substitute for a durable task queue: if the master crashes mid-deploy, the wizard sees FAILED on refresh and the operator retries. Idempotent + cheap; runs unconditionally including in contract-test mode.
This commit is contained in:
41
decnet/web/router/fleet/api_lifecycle.py
Normal file
41
decnet/web/router/fleet/api_lifecycle.py
Normal file
@@ -0,0 +1,41 @@
|
||||
"""GET /deckies/lifecycle?ids=… — poll lifecycle rows by id.
|
||||
|
||||
The wizard polls this endpoint every ~2 s after POSTing /deckies/deploy
|
||||
or /deckies/{name}/mutate (which return 202 with the lifecycle ids) and
|
||||
stops when every row reaches a terminal status.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
|
||||
from decnet.logging import get_logger
|
||||
from decnet.telemetry import traced as _traced
|
||||
from decnet.web.db.models import DeckyLifecycleListResponse, DeckyLifecycleView
|
||||
from decnet.web.dependencies import require_viewer, repo
|
||||
|
||||
log = get_logger("api.lifecycle")
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get(
|
||||
"/deckies/lifecycle",
|
||||
tags=["Fleet Management"],
|
||||
response_model=DeckyLifecycleListResponse,
|
||||
responses={
|
||||
401: {"description": "Could not validate credentials"},
|
||||
422: {"description": "Validation error (ids missing or malformed)"},
|
||||
},
|
||||
)
|
||||
@_traced("api.lifecycle_get")
|
||||
async def api_get_lifecycle(
|
||||
ids: list[str] = Query(
|
||||
..., description="One or more DeckyLifecycle row ids; pass repeated ?ids=<uuid>&ids=<uuid> in the URL.",
|
||||
min_length=1, max_length=200,
|
||||
),
|
||||
user: dict = Depends(require_viewer),
|
||||
) -> dict:
|
||||
rows = await repo.get_lifecycle_by_ids(ids)
|
||||
return {
|
||||
"rows": [DeckyLifecycleView(**r).model_dump() for r in rows],
|
||||
}
|
||||
Reference in New Issue
Block a user