implmentace plan guardu
Some checks failed
CI and deploy / migration-check (push) Failing after 17s
CI and deploy / deploy (push) Has been skipped

This commit is contained in:
Dusan Vojacek
2026-04-19 23:10:25 +02:00
parent d8221e3169
commit e3776226a4
9 changed files with 369 additions and 7 deletions

View File

@@ -19,6 +19,7 @@ from app.deps import set_pg_pool
from app.refresh_negative_prices import refresh_negative_price_predictions
from app.ws_log_handler import WSLogHandler
from services.audit_filler import fill_audit_for_completed_intervals
from services.plan_actual_slot_guard import run_plan_actual_slot_guard_for_all_active_sites
from services.control_exporter import export_setpoints, verify_modbus_commands
from services.forecast_service import fetch_pv_forecast
from services.heartbeat_service import send_heartbeat
@@ -75,6 +76,13 @@ async def lifespan(app: FastAPI):
except Exception:
logger.exception("scheduled_audit_filler site=%s failed", site["id"])
async def scheduled_plan_actual_slot_guard() -> None:
"""Po audit filleru: fatální odchylka plán vs. skutečnost (síť) → Discord (dedup v DB)."""
try:
await run_plan_actual_slot_guard_for_all_active_sites(app.state.pg_pool)
except Exception:
logger.exception("scheduled_plan_actual_slot_guard failed")
async def scheduled_forecast_accuracy() -> None:
async with app.state.pg_pool.acquire() as conn:
for site in await _active_site_rows(conn):
@@ -306,6 +314,14 @@ async def lifespan(app: FastAPI):
second=0,
id="audit_filler",
)
scheduler.add_job(
scheduled_plan_actual_slot_guard,
"cron",
minute="5,20,35,50",
second=0,
id="plan_actual_slot_guard",
replace_existing=True,
)
scheduler.add_job(
scheduled_forecast_accuracy,
"cron",