From bfc960233b770f39b34f970c6cd5d13c319f66ee Mon Sep 17 00:00:00 2001 From: zosimovaa Date: Fri, 27 Feb 2026 19:34:50 +0300 Subject: [PATCH] =?UTF-8?q?FEAT-1.=20=D0=9E=D0=BF=D0=B8=D1=81=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20readme.md=20=D0=BD=D0=B0=20=D0=B0=D0=BD=D0=B3?= =?UTF-8?q?=D0=BB=D0=B9=D0=B8=D1=81=D0=BA=D0=BE=D0=BC=20=D1=8F=D0=B7=D1=8B?= =?UTF-8?q?=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/README.md b/README.md index 32fccd8..a7ad9d1 100644 --- a/README.md +++ b/README.md @@ -208,4 +208,51 @@ classDiagram - **e-mail**: lesha.spb@gmail.com - **telegram**: https://t.me/lesha_spb +--- +## Description (English) + +**Config Manager** is a Python package for running applications with periodic execution logic, config reload, and control via HTTP API (and optionally Telegram). + +**Contract:** Your application subclasses **ConfigManagerV2** and overrides **execute()** (periodic work). Control (start/stop, health) is done via channels that are created externally and passed into the constructor as **control_channels** (e.g. **HttpControlChannel** for REST API). + +### Architecture and components + +**ConfigManager** (class **ConfigManagerV2**) is the application entry point. It inherits internal logic from **_RuntimeController** (worker and config-update loops, starting/stopping control channels). + +**Core:** +- **ConfigLoader** — reads config from file (YAML/JSON), computes hash and returns config only when changed; on parse error returns last valid config. +- **WorkerLoop** — in a separate thread, repeatedly calls your **execute()** with a pause; reacts to stop event and success/error callbacks. +- **LogManager** — applies the **log** section from config to logging (dictConfig). +- **HealthAggregator** — aggregates state: lifecycle (idle/starting/running/…), last successful **execute()** time and health timeout; produces a single health response (ok/unhealthy). +- **ControlChannelBridge** — single bridge for all channels: on_start/on_stop/on_status handlers (halt flag and status text). + +**Control channels:** +- **ControlChannel** — abstract contract: **start(on_start, on_stop, on_status)**, **stop()**. +- **HttpControlChannel** — HTTP API (**/health**, **/actions/start**, **/actions/stop**, **/actions/status**); uses **UvicornServerRunner**; **/health** calls **HealthAggregator.collect()**, actions use handlers from **ControlChannelBridge**. +- **TelegramControlChannel** — implementation via Telegram long polling; commands **/start**, **/stop**, **/status** invoke the same handlers. + +**Flow:** On **start()** the manager starts all channels from **control_channels**, then runs two loops: **WorkerLoop** and periodic config refresh via **ConfigLoader**. API control: **/health**, **/actions/start**, **/actions/stop** when **HttpControlChannel** is in **control_channels**. Halt stops both loops; then all channels are stopped. + +### Running with ConfigManagerV2 and HttpControlChannel + +1. Subclass **ConfigManagerV2** and implement **execute()** (your periodic logic). Optionally override **get_health_status()** for custom **/health** response. +2. Create channels externally and pass them to the constructor. For HTTP API create **HttpControlChannel**; for health the manager’s callback is needed — pass **control_channels** as a factory (lambda that receives the manager). +3. Start from an async context: **await app.start()** or **asyncio.create_task(app.start())** for background. Stop: **await app.stop()** or HTTP **/actions/stop**. + +See the minimal example in the Russian section above; a full example is in **tests/test_app.py**. + +### Logging + +Logging is configured from the config file only if it contains a **log** section in [dictConfig](https://docs.python.org/3/library/logging.config.html#logging.config.dictConfig) format. If **log** is missing, the manager logs a warning and the default Python level (WARNING) remains. + +### Installation + +```bash +pip install git+https://git.lesha.spb.ru/alex/config_manager.git +``` + +### Contacts + +- **e-mail**: lesha.spb@gmail.com +- **telegram**: https://t.me/lesha_spb