From 79bd2939c37ffd06c000d87d82c0b8d56125bf51 Mon Sep 17 00:00:00 2001 From: demo-bot Date: Sun, 9 Aug 2026 16:00:49 +0000 Subject: [PATCH] decomposer: generate deliverable files for Define the service contract and project architecture for the FastAPI endpoint monitoring service.; Implement the typed monitor CRUD API and concurrency-safe in-memory state according to the service design.; Implement secure on-demand endpoint checks with status updates, latency measurement, robust error handling, and redacted structured logs.; Add operational API endpoints and environment-driven runtime configuration to the monitoring service.; Create automated tests for the monitoring service.; Package the service with Docker and developer documentation.; Validate the complete project. --- app/models.py | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/app/models.py b/app/models.py index d3c8f4a..3d2910a 100644 --- a/app/models.py +++ b/app/models.py @@ -1,33 +1,34 @@ from datetime import datetime -from enum import StrEnum +from typing import Literal from uuid import UUID -from pydantic import AnyHttpUrl, BaseModel, ConfigDict, Field +from pydantic import AnyHttpUrl, BaseModel, ConfigDict, Field, model_validator + +StatusState = Literal["unknown", "up", "down", "error"] -class MonitorState(StrEnum): - UNKNOWN = "unknown" - UP = "up" - DOWN = "down" - ERROR = "error" - BLOCKED = "blocked" +class CheckStatus(BaseModel): + state: StatusState = "unknown" + checked_at: datetime | None = None + status_code: int | None = None + latency_ms: float | None = Field(default=None, ge=0) + error: str | None = None class MonitorCreate(BaseModel): - name: str = Field(min_length=1, max_length=100) + name: str = Field(min_length=1, max_length=200) url: AnyHttpUrl -class MonitorUpdate(MonitorCreate): - pass +class MonitorUpdate(BaseModel): + name: str | None = Field(default=None, min_length=1, max_length=200) + url: AnyHttpUrl | None = None - -class StatusSnapshot(BaseModel): - state: MonitorState = MonitorState.UNKNOWN - checked_at: datetime | None = None - latency_ms: float | None = Field(default=None, ge=0) - http_status: int | None = Field(default=None, ge=100, le=599) - error: str | None = None + @model_validator(mode="after") + def not_empty(self) -> "MonitorUpdate": + if self.name is None and self.url is None: + raise ValueError("at least one field is required") + return self class Monitor(BaseModel): @@ -38,8 +39,13 @@ class Monitor(BaseModel): url: AnyHttpUrl created_at: datetime updated_at: datetime - status: StatusSnapshot + status: CheckStatus -class Health(BaseModel): - status: str +class CheckResult(CheckStatus): + monitor_id: UUID + status_applied: bool = True + + +class HealthResponse(BaseModel): + status: Literal["ok", "ready"]