55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
# import os
|
|
# os.chdir(os.path.dirname(__file__))
|
|
|
|
import asyncio
|
|
import logging
|
|
from pathlib import Path
|
|
|
|
from config_manager import ConfigManager
|
|
from config_manager.v2.control import HttpControlChannel
|
|
|
|
logger = logging.getLogger()
|
|
|
|
|
|
class MyApp(ConfigManager):
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.iter = 0
|
|
|
|
def execute(self) -> None:
|
|
"""Успешный прогон сбрасывает таймер health (обновляет время последнего успеха)."""
|
|
#logger.critical("current iteration %s", self.iter)
|
|
#logger.error("current iteration %s", self.iter)
|
|
logger.warning("current iteration %s", self.iter)
|
|
#logger.info("current iteration %s", self.iter)
|
|
#logger.debug("current iteration %s", self.iter)
|
|
self.iter += 1
|
|
|
|
|
|
async def main() -> None:
|
|
config_path = Path(__file__).parent / "config.yaml"
|
|
print(config_path)
|
|
app = MyApp(
|
|
str(config_path),
|
|
control_channels=lambda m: [
|
|
HttpControlChannel(
|
|
host="0.0.0.0",
|
|
port=8000,
|
|
timeout=3,
|
|
health_provider=m.get_health_provider(),
|
|
)
|
|
],
|
|
)
|
|
logger.info("App starting")
|
|
# Менеджер запускаем в фоне (start() не возвращает управление до stop).
|
|
asyncio.create_task(app.start())
|
|
|
|
logger.info("App running; Ctrl+C to stop")
|
|
while True:
|
|
await asyncio.sleep(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
logging.basicConfig(level=logging.INFO)
|
|
asyncio.run(main())
|