Integrate task runner into python tools

This commit is contained in:
ajp_anton
2026-08-08 17:21:50 +00:00
parent f8fb1eed75
commit 56d6194324
22 changed files with 1137 additions and 7 deletions
+58
View File
@@ -0,0 +1,58 @@
"""Runtime configuration."""
from __future__ import annotations
import os
import sys
from dataclasses import dataclass
from pathlib import Path
@dataclass(frozen=True)
class Settings:
task_root: Path
state_root: Path
credentials_root: Path
python_executable: str
timezone_name: str | None
allowed_proxy_ips: frozenset[str]
cancel_grace_seconds: float
@property
def database_path(self) -> Path:
return self.state_root / "server-maintenance.sqlite3"
@classmethod
def from_environment(cls) -> "Settings":
allowed_proxy_ips = frozenset(
value.strip()
for value in os.environ.get(
"SERVER_MAINTENANCE_ALLOWED_PROXY_IPS", ""
).split(",")
if value.strip()
)
return cls(
task_root=Path(
os.environ.get("SERVER_MAINTENANCE_TASK_ROOT", "/opt/tasks")
),
state_root=Path(
os.environ.get(
"SERVER_MAINTENANCE_STATE_ROOT",
"/var/lib/server-maintenance",
)
),
credentials_root=Path(
os.environ.get(
"SERVER_MAINTENANCE_CREDENTIALS_ROOT",
"/opt/credentials",
)
),
python_executable=os.environ.get(
"SERVER_MAINTENANCE_PYTHON", sys.executable
),
timezone_name=os.environ.get("TZ") or None,
allowed_proxy_ips=allowed_proxy_ips,
cancel_grace_seconds=float(
os.environ.get("SERVER_MAINTENANCE_CANCEL_GRACE_SECONDS", "10")
),
)