Add optional legacy workstream_id metering hook to progress router
All checks were successful
CI Smoke / host-smoke (push) Successful in 1s
CI Smoke / container-smoke (push) Successful in 4s

create_progress_router accepts meter_legacy_workstream_id so host apps
like state-hub can record Deprecation usage when callers filter progress
events with the legacy query param.
This commit is contained in:
tegwick 2026-07-08 22:29:21 +02:00
parent 693189997f
commit c804f06b67

View file

@ -1,9 +1,9 @@
import uuid
from collections.abc import Callable, Collection
from collections.abc import Awaitable, Callable, Collection
from datetime import datetime
from typing import Any
from fastapi import APIRouter, Depends, HTTPException, Query, status
from fastapi import APIRouter, Depends, HTTPException, Query, Request, Response, status
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
@ -16,12 +16,19 @@ from hub_core.utils.pagination import PageParams, apply_pagination
# ``workstream_id`` remains a wire-compat alias until legacy-meter retires it.
MeterLegacyWorkstreamId = Callable[
[AsyncSession, Request, Response],
Awaitable[None],
]
def create_progress_router(
get_session: Callable[..., AsyncSession],
*,
progress_model: type[ProgressEvent] = ProgressEvent,
progress_create_schema: type[ProgressEventCreate] = ProgressEventCreate,
progress_read_schema: type[ProgressEventRead] = ProgressEventRead,
meter_legacy_workstream_id: MeterLegacyWorkstreamId | None = None,
) -> APIRouter:
router = APIRouter(prefix="/progress", tags=["progress"])
list_response_model = list[progress_read_schema]
@ -78,6 +85,8 @@ def create_progress_router(
@router.get("/", response_model=list_response_model)
async def list_progress(
request: Request,
response: Response,
topic_id: uuid.UUID | None = None,
workstream_id: uuid.UUID | None = None,
workplan_id: uuid.UUID | None = None,
@ -89,6 +98,12 @@ def create_progress_router(
offset: int = Query(0, ge=0),
session: AsyncSession = Depends(get_session),
) -> list[Any]:
if (
meter_legacy_workstream_id is not None
and workstream_id is not None
and workplan_id is None
):
await meter_legacy_workstream_id(session, request, response)
return await _list_events(
session,
topic_id=topic_id,