Files
plba_v2/src/plba/runtime/worker/models.py
T
2026-10-10 19:36:32 +03:00

49 lines
1.1 KiB
Python

from collections.abc import Awaitable, Callable, Mapping
from dataclasses import dataclass, field
from enum import StrEnum
from typing import Any
class HealthStatus(StrEnum):
OK = "ok"
DEGRADED = "degraded"
UNHEALTHY = "unhealthy"
class WorkerLifecycle(StrEnum):
NEW = "new"
STARTING = "starting"
RUNNING = "running"
STOPPING = "stopping"
STOPPED = "stopped"
FAILED = "failed"
@dataclass(frozen=True, slots=True)
class ComponentHealth:
status: HealthStatus = HealthStatus.OK
critical: bool = True
detail: str | None = None
meta: Mapping[str, Any] = field(default_factory=dict)
HealthCheck = Callable[[], Awaitable[ComponentHealth]]
WorkerProcess = Callable[[], Awaitable[None]]
@dataclass(frozen=True, slots=True)
class WorkerDefinition:
name: str
process: WorkerProcess
critical: bool = True
health_check: HealthCheck | None = None
@dataclass(frozen=True, slots=True)
class WorkerSnapshot:
name: str
lifecycle: WorkerLifecycle
health: ComponentHealth
last_error: BaseException | None = None