Skip to content

Commit

Permalink
create check_capacity helper, add details to message when at capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
eriktaubeneck committed Jul 17, 2024
1 parent 3e7257b commit b3d260b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
14 changes: 14 additions & 0 deletions sidecar/app/routes/http_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,17 @@ def get_query_from_query_id(
if query is None:
raise HTTPException(status_code=404, detail=f"Query<{query_id}> not found")
return query


def check_capacity(
query_manager: QueryManager,
) -> None:
if not query_manager.capacity_available:
raise HTTPException(
status_code=503,
detail=(
f"Capacity unavailable. Currently running "
f"{len(query_manager.running_queries)} of "
f"{query_manager.max_parallel_queries} queries."
),
)
14 changes: 6 additions & 8 deletions sidecar/app/routes/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
from pathlib import Path
from typing import Annotated

from fastapi import APIRouter, BackgroundTasks, Form, HTTPException, Request, status
from fastapi import APIRouter, BackgroundTasks, Form, Request, status
from fastapi.responses import StreamingResponse

from ..local_paths import Paths
from ..query.base import Query
from ..query.demo_logger import DemoLoggerQuery
from ..query.ipa import GateType, IPACoordinatorQuery, IPAHelperQuery
from ..settings import get_settings
from .http_helpers import get_query_from_query_id
from .http_helpers import check_capacity, get_query_from_query_id

router = APIRouter(
prefix="/start",
Expand Down Expand Up @@ -50,8 +50,8 @@ def demo_logger(
request: Request,
):
query_manager = request.app.state.QUERY_MANAGER
if not query_manager.capacity_available:
raise HTTPException(status_code=503, detail="Capacity unavailable")
check_capacity(query_manager)

query = DemoLoggerQuery(
query_id=query_id,
num_lines=num_lines,
Expand All @@ -74,8 +74,7 @@ def start_ipa_helper(
):
# pylint: disable=too-many-arguments
query_manager = request.app.state.QUERY_MANAGER
if not query_manager.capacity_available:
raise HTTPException(status_code=503, detail="Capacity unavailable")
check_capacity(query_manager)

settings = get_settings()
role = settings.role
Expand Down Expand Up @@ -164,8 +163,7 @@ def start_ipa_query(
):
# pylint: disable=too-many-arguments
query_manager = request.app.state.QUERY_MANAGER
if not query_manager.capacity_available:
raise HTTPException(status_code=503, detail="Capacity unavailable")
check_capacity(query_manager)

settings = get_settings()
role = settings.role
Expand Down

0 comments on commit b3d260b

Please sign in to comment.