diff options
| author | Guillermo Serrahima <dev@vylion.com> | 2026-06-29 10:33:07 +0200 |
|---|---|---|
| committer | Guillermo Serrahima <dev@vylion.com> | 2026-07-01 12:41:03 +0200 |
| commit | 7cc411acbf4f709e39da5eef9ecc1ab19ac3d3fa (patch) | |
| tree | 133d26bee893286db72fd9cb2a3fa6ee1d6a0dcd /scripts | |
| parent | 9d9151ba6e6c06fe213d20f5e4aaabbec6750946 (diff) | |
| download | senia-7cc411acbf4f709e39da5eef9ecc1ab19ac3d3fa.tar.xz senia-7cc411acbf4f709e39da5eef9ecc1ab19ac3d3fa.zip | |
Updated heartbeat quiet hours
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/heartbeat.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/scripts/heartbeat.py b/scripts/heartbeat.py index 062cecb..5fe321b 100644 --- a/scripts/heartbeat.py +++ b/scripts/heartbeat.py @@ -12,7 +12,7 @@ import subprocess import sys import urllib.request from email.header import Header -from datetime import datetime, timedelta, timezone +from datetime import time, datetime, timedelta, timezone from pathlib import Path # ---------- config ---------- @@ -22,7 +22,8 @@ STATE_DIR = Path("/etc/senia/data/heartbeat") LAST_WAKE_FILE = STATE_DIR / "last_wake_at" WORKSPACE = Path("/workspace") -QUIET_MAX_HOURS = 4 +QUIET_MIN_HOURS = 2.5 +QUIET_MAX_HOURS = QUIET_MIN_HOURS * 2 NTFY_URL = os.environ["NTFY_URL"] # e.g. https://ntfy.example.tld/senia NTFY_TOKEN = os.environ["NTFY_TOKEN"] @@ -63,7 +64,9 @@ def should_wake(tasks, last_wake, now) -> tuple[bool, str]: if last_wake is None: return True, "First wake-up since the script was set up." elapsed = now - last_wake - if elapsed >= timedelta(hours=QUIET_MAX_HOURS): + now = datetime.now().time() + quiet_hours = QUIET_MAX_HOURS if (now >= time(22) or now < time(7)) else QUIET_MIN_HOURS + if elapsed >= timedelta(hours=quiet_hours): hrs = elapsed.total_seconds() / 3600 return True, f"It's been {hrs:.1f} hours since the last check-in." return False, "" |
