Coverage for app / router / monitoring / response.py: 100%
42 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-10-31 11:21 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-10-31 11:21 +0000
1from pydantic import BaseModel
2from app.util.types.enum import XStrEnum
3from app.common.settings import get_settings
4from app.util.time import UTCDateTime
7class ServiceStatus(XStrEnum):
8 OK = "ok"
9 DEGRADED = "degraded"
10 DOWN = "down"
13class Status(BaseModel):
14 status: ServiceStatus
17class ServiceStatuses(BaseModel):
18 database: ServiceStatus
21class Health(Status):
22 uptime: float
23 timestamp: UTCDateTime
24 services: ServiceStatuses
25 version: str = get_settings().APP_VERSION
28class ScheduledJobStatus(BaseModel):
29 """One background job, and how its last run went."""
31 key: str
32 label: str
33 description: str = ""
34 #: What the job asks for, and what the tick interval actually allows.
35 interval_seconds: int
36 effective_interval_seconds: int
37 last_started_at: UTCDateTime | None = None
38 last_finished_at: UTCDateTime | None = None
39 last_duration_ms: int | None = None
40 last_status: str | None = None
41 last_detail: str | None = None
42 #: Not cleared by a later success — "working now but failed at 03:00" is
43 #: a different statement from "has never failed".
44 last_error: str | None = None
45 last_error_at: UTCDateTime | None = None
46 run_count: int = 0
47 failure_count: int = 0
50class SchedulerStatus(BaseModel):
51 """Whether this replica is scheduling, and what it has run."""
53 enabled: bool
54 running: bool
55 #: Exactly one replica leads. False is the normal state everywhere else;
56 #: false on *every* replica is the condition worth alerting on.
57 leader: bool
58 tick_seconds: int | None = None
59 jobs: list[ScheduledJobStatus] = []
62class Response:
63 Ping = Status
64 Health = Health
65 Scheduler = SchedulerStatus