"""Batch-check add-on. On unless SINETTI_BATCH_CHECK_ENABLED is explicitly off.""" from __future__ import annotations import os from collections.abc import Mapping from dataclasses import dataclass from fastapi import FastAPI _OFF = frozenset({"0", "false", "no", "off"}) @dataclass(frozen=True) class BatchCheckStatus: active: bool reason: str def deployment_requested(environ: Mapping[str, str] | None = None) -> bool: source = os.environ if environ is None else environ raw = source.get("SINETTI_BATCH_CHECK_ENABLED", "").strip().casefold() return raw not in _OFF def status() -> BatchCheckStatus: if deployment_requested(): return BatchCheckStatus(True, "active") return BatchCheckStatus(False, "deployment_disabled") def register(app: FastAPI, dependencies: list) -> BatchCheckStatus: current = status() if not current.active: return current from sinetti_api.routers import batch_check app.include_router(batch_check.router, dependencies=dependencies) return current