ci / contract (сгенерированный код совпадает с openapi.yaml) (push) Successful in 3m55s
ci / api (push) Successful in 51s
ci / mobile (Metro-бандл Android) (push) Canceled after 0s
release / images (services/api/Dockerfile, storage-agent, storage-agent) (push) Canceled after 0s
release / images (services/recommender/Dockerfile, recommender, ) (push) Canceled after 0s
ci / recommender (push) Successful in 1m11s
ci / ts (packages + web) (push) Canceled after 3s
release / verify (push) Successful in 1m16s
release / images (apps/web/Dockerfile, web, ) (push) Failing after 2m40s
release / android + release (push) Skipped
release / images (services/api/Dockerfile, api, api) (push) Canceled after 1s
- api/openapi.yaml: contract with /healthz, /readyz, /api/v1/server-info - services/api (Go): api with oapi-codegen strict server, goose migrations, readiness checks for Postgres/Redis; storage-agent stub with internal token - services/recommender (Python, uv): FastAPI health/readiness/internal status, `pipu-rec serve` and `pipu-rec analyze` entrypoints - packages: generated api-client, core (server URL + server check), i18n (ru/en + dictionary check), design-tokens (CSS vars + TS from tokens.json) - apps/web: Vite + React shell showing server status, language switch - apps/mobile: Expo (SDK 53) Android app with server connect screen - deploy: Dockerfiles, compose (prod + dev), nginx template, install/update scripts - .gitea/workflows: ci.yml and tag-based release.yml (images, signed APK, release) - scripts/version.mjs: version and Android versionCode from git tag - tests/fixtures/music/generate.sh: synthetic test library via ffmpeg - docs: versionCode formula, OpenAPI 3.0.3, dev instructions in README Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
1.8 KiB
Python
49 lines
1.8 KiB
Python
"""FastAPI-приложение внутреннего API рекомендаций."""
|
|
|
|
import hmac
|
|
from collections.abc import Awaitable, Callable
|
|
from typing import Annotated
|
|
|
|
from fastapi import Depends, FastAPI, Header, HTTPException, status
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from pipu_rec.settings import Settings
|
|
|
|
Check = Callable[[], Awaitable[None]]
|
|
|
|
|
|
def create_app(settings: Settings, checks: dict[str, Check] | None = None) -> FastAPI:
|
|
app = FastAPI(title="pipu-recommender", version=settings.version, docs_url=None, redoc_url=None)
|
|
checks = checks or {}
|
|
|
|
def require_token(authorization: Annotated[str, Header()] = "") -> None:
|
|
scheme, _, token = authorization.partition(" ")
|
|
expected = settings.internal_token
|
|
if scheme != "Bearer" or not expected or not hmac.compare_digest(token, expected):
|
|
raise HTTPException(status.HTTP_401_UNAUTHORIZED, detail="auth.invalid_internal_token")
|
|
|
|
@app.get("/healthz")
|
|
async def healthz() -> dict[str, str]:
|
|
return {"status": "ok"}
|
|
|
|
@app.get("/readyz")
|
|
async def readyz() -> JSONResponse:
|
|
results: dict[str, str] = {}
|
|
for name, check in checks.items():
|
|
try:
|
|
await check()
|
|
results[name] = "ok"
|
|
except Exception as exc:
|
|
results[name] = str(exc) or type(exc).__name__
|
|
healthy = all(v == "ok" for v in results.values())
|
|
return JSONResponse(
|
|
{"status": "ok" if healthy else "degraded", "checks": results},
|
|
status_code=status.HTTP_200_OK if healthy else status.HTTP_503_SERVICE_UNAVAILABLE,
|
|
)
|
|
|
|
@app.get("/internal/status", dependencies=[Depends(require_token)])
|
|
async def internal_status() -> dict[str, object]:
|
|
return {"version": settings.version, "models": [], "ranker": "heuristic-v1"}
|
|
|
|
return app
|