PLBA2-2. Реализация

This commit is contained in:
2026-10-10 19:36:32 +03:00
parent 473cde126f
commit 71998a6b13
120 changed files with 3675 additions and 21 deletions
+35
View File
@@ -0,0 +1,35 @@
from collections.abc import Awaitable, Callable
from dataclasses import dataclass
from plba.runtime.worker.models import ComponentHealth
HealthReader = Callable[[], Awaitable[ComponentHealth]]
@dataclass(frozen=True, slots=True)
class HealthContributor:
name: str
health_reader: HealthReader
critical: bool = True
class DuplicateHealthContributorError(ValueError):
pass
class HealthContributorRegistry:
def __init__(self) -> None:
self._contributors: dict[str, HealthContributor] = {}
def register(self, contributor: HealthContributor) -> None:
if not contributor.name or contributor.name.strip() != contributor.name:
raise ValueError("health contributor name must be non-empty")
if contributor.name in self._contributors:
raise DuplicateHealthContributorError(
f"health contributor already registered: {contributor.name}"
)
self._contributors[contributor.name] = contributor
def all(self) -> tuple[HealthContributor, ...]:
return tuple(self._contributors.values())