Add optional legacy workstream_id metering hook to progress router
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:
parent
693189997f
commit
c804f06b67
1 changed files with 17 additions and 2 deletions
|
|
@ -1,9 +1,9 @@
|
||||||
import uuid
|
import uuid
|
||||||
from collections.abc import Callable, Collection
|
from collections.abc import Awaitable, Callable, Collection
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any
|
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 import select
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
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.
|
# ``workstream_id`` remains a wire-compat alias until legacy-meter retires it.
|
||||||
|
|
||||||
|
|
||||||
|
MeterLegacyWorkstreamId = Callable[
|
||||||
|
[AsyncSession, Request, Response],
|
||||||
|
Awaitable[None],
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def create_progress_router(
|
def create_progress_router(
|
||||||
get_session: Callable[..., AsyncSession],
|
get_session: Callable[..., AsyncSession],
|
||||||
*,
|
*,
|
||||||
progress_model: type[ProgressEvent] = ProgressEvent,
|
progress_model: type[ProgressEvent] = ProgressEvent,
|
||||||
progress_create_schema: type[ProgressEventCreate] = ProgressEventCreate,
|
progress_create_schema: type[ProgressEventCreate] = ProgressEventCreate,
|
||||||
progress_read_schema: type[ProgressEventRead] = ProgressEventRead,
|
progress_read_schema: type[ProgressEventRead] = ProgressEventRead,
|
||||||
|
meter_legacy_workstream_id: MeterLegacyWorkstreamId | None = None,
|
||||||
) -> APIRouter:
|
) -> APIRouter:
|
||||||
router = APIRouter(prefix="/progress", tags=["progress"])
|
router = APIRouter(prefix="/progress", tags=["progress"])
|
||||||
list_response_model = list[progress_read_schema]
|
list_response_model = list[progress_read_schema]
|
||||||
|
|
@ -78,6 +85,8 @@ def create_progress_router(
|
||||||
|
|
||||||
@router.get("/", response_model=list_response_model)
|
@router.get("/", response_model=list_response_model)
|
||||||
async def list_progress(
|
async def list_progress(
|
||||||
|
request: Request,
|
||||||
|
response: Response,
|
||||||
topic_id: uuid.UUID | None = None,
|
topic_id: uuid.UUID | None = None,
|
||||||
workstream_id: uuid.UUID | None = None,
|
workstream_id: uuid.UUID | None = None,
|
||||||
workplan_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),
|
offset: int = Query(0, ge=0),
|
||||||
session: AsyncSession = Depends(get_session),
|
session: AsyncSession = Depends(get_session),
|
||||||
) -> list[Any]:
|
) -> 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(
|
return await _list_events(
|
||||||
session,
|
session,
|
||||||
topic_id=topic_id,
|
topic_id=topic_id,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue