Refactor cron to call API via HTTP, capture base_url from browser
CI / test-and-package (push) Successful in 33s

- meal-cron now runs send_reminders_cron.sh (simple wget loop, no DB mount)
- New /api/cron-tick endpoint handles all timezone logic server-side
- base_url captured from request.host_url when user saves ntfy settings,
  stored per-user — no APP_BASE_URL env var needed
- Cron endpoint protected by CRON_SECRET shared env var
- Removed send_reminders_cron.py, DB volume from cron container
- tests: 3 new cron-tick + base_url capture tests (69 total)
This commit is contained in:
agentbox
2026-08-01 06:32:09 +00:00
parent 2cd435daf2
commit 710cd1fbf9
9 changed files with 161 additions and 102 deletions
+3 -2
View File
@@ -34,13 +34,14 @@ def create_app() -> Flask:
def send_reminders_command(date, meal, base_url):
"""Send ntfy meal reminders to all users who have ntfy configured."""
target_date = date and __import__("datetime").datetime.strptime(date, "%Y-%m-%d").date() or date.today()
app_base_url = base_url or os.environ.get("APP_BASE_URL", "http://localhost:5000")
fallback_url = base_url or os.environ.get("APP_BASE_URL", "http://localhost:5000")
meal_types = ["lunch", "dinner"] if meal == "both" else [meal]
total_sent = 0
for household in get_all_households():
for user in get_users_with_ntfy(household["id"]):
user_base_url = user.get("base_url") or fallback_url
for mt in meal_types:
ok = send_meal_reminder(
ntfy_url=user["ntfy_url"],
@@ -48,7 +49,7 @@ def create_app() -> Flask:
callback_token=user["callback_token"],
meal_type=mt,
for_date=target_date,
app_base_url=app_base_url,
app_base_url=user_base_url,
)
if ok:
total_sent += 1