Files
site/WESP_REL/app/runtime_services.py
2026-07-17 12:57:18 +03:00

40 lines
1.2 KiB
Python

"""Фоновые сервисы после готовности приложения (sync, OTA, LLM)."""
from __future__ import annotations
import atexit
from flask import Flask
def schedule_runtime_services(app: Flask) -> None:
if app.config.get("TESTING"):
return
if app.config.get("SYNC_CLIENT_AUTOSTART", True):
from app.services.startup_defer import default_startup_delay_sec
from sync_client import schedule_sync_client_autostart, stop_sync_client
sync_delay = default_startup_delay_sec(
"WESP_STARTUP_SYNC_DELAY_SEC", arm_default=3.0, other_default=0.6
)
schedule_sync_client_autostart(app, delay_sec=sync_delay)
atexit.register(stop_sync_client)
from app.services.auto_update_runtime import (
register_update_checker_shutdown,
schedule_update_checker,
)
schedule_update_checker(app)
register_update_checker_shutdown()
if app.config.get("WESP_LLM_AUTOSTART"):
from app.services.local_llm_autostart import (
schedule_llm_server_autostart,
stop_llm_server_process,
)
schedule_llm_server_autostart(app)
atexit.register(stop_llm_server_process)