-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.py
More file actions
41 lines (31 loc) · 1.09 KB
/
entrypoint.py
File metadata and controls
41 lines (31 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
"""
entrypoint.py — daemon loop for containerised deployments.
Runs collect + alerts on a fixed interval (default 30 min).
Logs go to stdout so `docker logs` / `docker compose logs` works as expected.
"""
import os
import subprocess
import sys
import time
INTERVAL = int(os.environ.get("RUN_INTERVAL_SECONDS", "1800"))
CONFIG = os.environ.get("CONFIG", "config.yaml")
PYTHON = sys.executable
def run(mode: str, extra: list[str] | None = None) -> int:
cmd = [PYTHON, "watch.py", "--config", CONFIG, "--mode", mode] + (extra or [])
result = subprocess.run(cmd)
return result.returncode
def main() -> None:
print(
f"[entrypoint] topic-watch starting — config={CONFIG} interval={INTERVAL}s",
flush=True,
)
while True:
print("[entrypoint] running collect …", flush=True)
run("collect")
print("[entrypoint] running alerts …", flush=True)
run("alerts", ["--send-telegram"])
print(f"[entrypoint] sleeping {INTERVAL}s …", flush=True)
time.sleep(INTERVAL)
if __name__ == "__main__":
main()