From b8445a1bb3e5d1c761b0e059fb39a7e1832566db Mon Sep 17 00:00:00 2001 From: Holden Date: Wed, 10 Jun 2026 16:48:10 -0400 Subject: [PATCH] fix cron --- scheduler.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 scheduler.py diff --git a/scheduler.py b/scheduler.py new file mode 100644 index 0000000..a6ec20a --- /dev/null +++ b/scheduler.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +""" +Simple in-container scheduler using croniter + sleep. +No cron daemon, no sudo, no root needed. +""" + +import os +import sys +import subprocess +import time + +try: + from croniter import croniter +except ImportError: + print("❌ croniter not installed. Run: uv add croniter") + sys.exit(1) + +SCHEDULE = os.environ["CRON_SCHEDULE"] +NOW = time.time() + +cron = croniter(SCHEDULE, NOW) +next_run = cron.get_next(float) + +while True: + now = time.time() + if now >= next_run: + print(f"\n▶ [{time.strftime('%Y-%m-%d %H:%M:%S')}] Starting if-curator...") + result = subprocess.run(["uv", "run", "if-curator"]) + if result.returncode == 0: + print(f"✅ Run complete.") + else: + print(f"⚠️ Run exited with code {result.returncode}") + + next_run = cron.get_next(float) + wait = next_run - time.time() + if wait > 0: + print(f"▶ Next run: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(next_run))} (in {int(wait // 3600)}h {int((wait % 3600) // 60)}m)") + continue + + wait = next_run - now + print(f"▶ Next run: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(next_run))} (in {int(wait // 3600)}h {int((wait % 3600) // 60)}m)") + time.sleep(min(wait, 3600)) # Check every hour at most, or sooner if needed +