Refactor cron to call API via HTTP, capture base_url from browser
CI / test-and-package (push) Successful in 33s
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:
@@ -75,6 +75,8 @@ def init_db() -> None:
|
||||
db.execute("ALTER TABLE users ADD COLUMN ntfy_token TEXT DEFAULT ''")
|
||||
if "callback_token" not in cols:
|
||||
db.execute("ALTER TABLE users ADD COLUMN callback_token TEXT DEFAULT ''")
|
||||
if "base_url" not in cols:
|
||||
db.execute("ALTER TABLE users ADD COLUMN base_url TEXT DEFAULT ''")
|
||||
|
||||
# Migration: add timezone and reminder tracking to households
|
||||
hh_cols = [r["name"] for r in db.execute("PRAGMA table_info(households)").fetchall()]
|
||||
@@ -207,13 +209,13 @@ def get_household_users(household_id: int) -> list[dict]:
|
||||
# ── Ntfy / notifications ─────────────────────────────────────────────────────
|
||||
|
||||
def set_user_ntfy(user_id: int, ntfy_url: str, ntfy_token: str,
|
||||
callback_token: str) -> None:
|
||||
callback_token: str, base_url: str = "") -> None:
|
||||
"""Save ntfy settings for a user."""
|
||||
with get_db() as db:
|
||||
db.execute(
|
||||
"UPDATE users SET ntfy_url = ?, ntfy_token = ?, callback_token = ? "
|
||||
"WHERE id = ?",
|
||||
(ntfy_url, ntfy_token, callback_token, user_id),
|
||||
"UPDATE users SET ntfy_url = ?, ntfy_token = ?, callback_token = ?, "
|
||||
"base_url = ? WHERE id = ?",
|
||||
(ntfy_url, ntfy_token, callback_token, base_url, user_id),
|
||||
)
|
||||
|
||||
|
||||
@@ -221,7 +223,7 @@ def get_user_ntfy(user_id: int) -> dict:
|
||||
"""Get ntfy settings for a user."""
|
||||
with get_db() as db:
|
||||
row = db.execute(
|
||||
"SELECT ntfy_url, ntfy_token, callback_token FROM users WHERE id = ?",
|
||||
"SELECT ntfy_url, ntfy_token, callback_token, base_url FROM users WHERE id = ?",
|
||||
(user_id,),
|
||||
).fetchone()
|
||||
return dict(row) if row else {}
|
||||
@@ -241,7 +243,7 @@ def get_users_with_ntfy(household_id: int) -> list[dict]:
|
||||
"""Return all users in a household who have ntfy configured."""
|
||||
with get_db() as db:
|
||||
rows = db.execute(
|
||||
"SELECT id, username, ntfy_url, ntfy_token, callback_token "
|
||||
"SELECT id, username, ntfy_url, ntfy_token, callback_token, base_url "
|
||||
"FROM users WHERE household_id = ? "
|
||||
"AND ntfy_url != '' AND callback_token != '' "
|
||||
"ORDER BY username",
|
||||
|
||||
Reference in New Issue
Block a user