Большой рефакторинг с кодекс

This commit is contained in:
2026-02-26 22:05:21 +03:00
parent 2b43e2f86a
commit 170c81fc5b
2 changed files with 27 additions and 4 deletions

View File

@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
[project]
name = "config_manager"
version = "2.2.0"
description = "Большой рефакторинг"
version = "2.2.1"
description = "Большой рефакторинг, логирование"
authors = [
{ name = "Aleksei Zosimov", email = "lesha.spb@gmail.com" }
]

View File

@@ -89,6 +89,26 @@ class _RuntimeController:
timed_out_count,
)
async def _log_health_status_transition(self) -> None:
try:
health = await self._health_aggregator.collect()
except Exception: # noqa: BLE001
self.logger.exception("ConfigManagerV2._log_health_status_transition error")
return
status = health.get("status", "unhealthy")
if self._last_health_status == status:
return
previous = self._last_health_status or "unknown"
detail = health.get("detail", "")
self._last_health_status = status
self.logger.warning(
"ConfigManagerV2 health status changed: %s -> %s (state=%s detail=%s)",
previous,
status,
self._state.value,
detail,
)
async def _worker_loop(self) -> None:
self.logger.warning(
"ConfigManagerV2._worker_loop result: started work_interval=%s",
@@ -118,6 +138,7 @@ class _RuntimeController:
try:
while not self._halt.is_set():
await self._update_config()
await self._log_health_status_transition()
try:
await asyncio.wait_for(self._halt.wait(), timeout=max(self.update_interval, 0.05))
except asyncio.TimeoutError:
@@ -259,6 +280,7 @@ class _RuntimeController:
await self._update_config()
await self._start_control_channels()
await self._start_runtime()
await self._log_health_status_transition()
try:
await self._shutdown.wait()
@@ -320,6 +342,7 @@ class ConfigManagerV2(_RuntimeController):
self._worker_degraded = False
self._worker_inflight_count = 0
self._worker_timed_out_inflight_count = 0
self._last_health_status: Optional[str] = None
initial_config = self._loader.load_sync()
self.config = initial_config
@@ -373,7 +396,7 @@ class ConfigManagerV2(_RuntimeController):
self.logger.debug("ConfigManagerV2._update_config result: no changes")
return
self._apply_config(new_config)
self.logger.debug("ConfigManagerV2._update_config result: config updated")
self.logger.warning("ConfigManagerV2._update_config result: config updated and applied")
except Exception as exc: # noqa: BLE001
self.logger.exception("ConfigManagerV2._update_config error")
if self._loader.last_valid_config is None:
@@ -384,7 +407,7 @@ class ConfigManagerV2(_RuntimeController):
return
try:
self._apply_config(self._loader.last_valid_config)
self.logger.debug(
self.logger.warning(
"ConfigManagerV2._update_config result: fallback to last valid config applied",
)
except Exception: # noqa: BLE001