Implement balance monitoring and notification for Selectel API integration

- Added support for balance tracking using `SELECTEL_API_TOKEN` in the configuration.
- Introduced new balance notification logic in the local watchdog, alerting users on balance changes based on defined thresholds.
- Updated documentation to include instructions for setting up balance notifications and the required environment variables.
- Enhanced the `ready` and `session` modules to initialize balance state and handle notifications during GPU operations.
- Refactored the CLI and related components to support the new balance monitoring features, ensuring a seamless user experience.
This commit is contained in:
Leonid Pershin
2026-08-21 06:52:51 +03:00
parent 7ed6a99df2
commit 09b7c36f3b
14 changed files with 759 additions and 12 deletions
+12
View File
@@ -51,6 +51,12 @@ def _as_int(value: str | None, default: int) -> int:
return int(value)
def _as_float(value: str | None, default: float) -> float:
if value is None or str(value).strip() == "":
return default
return float(str(value).strip().replace(",", "."))
def _csv(value: str | None, default: tuple[str, ...]) -> tuple[str, ...]:
if value is None or value.strip() == "":
return default
@@ -114,6 +120,9 @@ class Config:
idle_grace_minutes: int
pull_output: bool
notify_ready: bool
selectel_api_token: str
balance_notify_step_rub: float
balance_notify_low_rub: float
missing: list[str] = field(default_factory=list)
@@ -245,5 +254,8 @@ def load_config(*, require_auth: bool = True) -> Config:
idle_grace_minutes=_as_int(os.environ.get("IDLE_GRACE_MINUTES"), 45),
pull_output=_as_bool(os.environ.get("PULL_OUTPUT"), False),
notify_ready=_as_bool(os.environ.get("NOTIFY_READY"), True),
selectel_api_token=(os.environ.get("SELECTEL_API_TOKEN") or "").strip(),
balance_notify_step_rub=_as_float(os.environ.get("BALANCE_NOTIFY_STEP_RUB"), 200.0),
balance_notify_low_rub=_as_float(os.environ.get("BALANCE_NOTIFY_LOW_RUB"), 0.0),
missing=missing,
)