Skip to content

Commit

Permalink
Add GitHub CI app info to /summary
Browse files Browse the repository at this point in the history
  • Loading branch information
fajpunk committed Jun 25, 2024
1 parent f351936 commit 9fe1559
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 5 deletions.
19 changes: 15 additions & 4 deletions src/mobu/handlers/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@

from ..config import config
from ..dependencies.context import RequestContext, context_dependency
from ..dependencies.github import maybe_ci_manager_dependency
from ..models import CombinedSummary
from ..models.flock import FlockConfig, FlockData, FlockSummary
from ..models.index import Index
from ..models.monkey import MonkeyData
from ..models.solitary import SolitaryConfig, SolitaryResult
from ..services.github_ci.ci_manager import CiManager

external_router = APIRouter(route_class=SlackRouteErrorHandler)
"""FastAPI router for all external handlers."""
Expand Down Expand Up @@ -239,10 +242,18 @@ async def put_run(
@external_router.get(
"/summary",
response_class=FormattedJSONResponse,
response_model=list[FlockSummary],
summary="Summary of statistics for all flocks",
response_model=CombinedSummary,
summary="Summary of all app state",
)
async def get_summary(
context: Annotated[RequestContext, Depends(context_dependency)],
) -> list[FlockSummary]:
return context.manager.summarize_flocks()
ci_manager: Annotated[
CiManager | None, Depends(maybe_ci_manager_dependency)
],
) -> CombinedSummary:
return CombinedSummary.model_validate(
{
"flocks": context.manager.summarize_flocks(),
"ci_manager": ci_manager.summarize if ci_manager else None,
}
)
17 changes: 17 additions & 0 deletions src/mobu/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Combinations of different models."""

from pydantic import BaseModel, Field

from .ci_manager import CiManagerSummary
from .flock import FlockSummary


class CombinedSummary(BaseModel):
"""Summary of all app state."""

flocks: list[FlockSummary] = Field(
..., title="Info about all running flocks"
)
ci_manager: CiManagerSummary | None = Field(
None, title="Info about GitHub CI workers"
)
47 changes: 47 additions & 0 deletions src/mobu/models/ci_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Models for CiManager."""

from pydantic import BaseModel, Field, HttpUrl

from .user import User

__all__ = [
"CiJobSummary",
"CiManagerSummary",
"CiWorkerSummary",
]


class CiJobSummary(BaseModel):
"""Information about a job."""

commit_url: HttpUrl = Field(
...,
title="GitHub URL to the commit being worked on",
)


class CiWorkerSummary(BaseModel):
"""Information about a running worker."""

user: User = Field(..., title="User that the worker works as")

num_processed: int = Field(
...,
title="Number of jobs this worker has processed since mobu started",
)

current_job: CiJobSummary | None = Field(
..., title="The job the worker is currently running, if any"
)


class CiManagerSummary(BaseModel):
"""Information about the CiManager."""

workers: list[CiWorkerSummary] = Field(
..., title="The workers being managed"
)

num_queued: int = Field(
..., title="Number of jobs waiting for a free worker"
)
2 changes: 1 addition & 1 deletion tests/handlers/flock_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async def test_start_stop_refresh(

r = await client.get("/mobu/summary")
assert r.status_code == 200
assert r.json() == [summary]
assert r.json() == {"flocks": [summary], "ci_manager": None}

r = await client.get("/mobu/flocks/other")
assert r.status_code == 404
Expand Down

0 comments on commit 9fe1559

Please sign in to comment.