Fix bot routine scheduling field mismatch and add debug logging

Bot was sending days_of_week/times but API expects days/time, so
bot-scheduled routines never got reminders. Also handle NULL frequency
from pre-migration rows and add detailed logging to routine reminder
checks for diagnosing further issues.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-20 00:21:22 -06:00
parent e89656a87c
commit 019561e7cd
2 changed files with 18 additions and 6 deletions

View File

@@ -217,12 +217,13 @@ async def handle_routine(message, session, parsed):
await message.channel.send("When should this routine be scheduled? (e.g., 'Monday Wednesday Friday at 7am')")
return
# Build schedule data
# Build schedule data (API expects "days" and "time")
schedule_data = {}
if days_of_week:
schedule_data["days_of_week"] = days_of_week
schedule_data["days"] = days_of_week
if times:
schedule_data["times"] = times
schedule_data["time"] = times[0]
schedule_data["remind"] = True
resp, status = api_request("put", f"/api/routines/{routine_id}/schedule", token, schedule_data)
if status == 200:

View File

@@ -123,20 +123,25 @@ def check_routine_reminders():
from datetime import date as date_type
schedules = postgres.select("routine_schedules", where={"remind": True})
logger.info(f"Routine reminders: found {len(schedules)} schedule(s) with remind=True")
for schedule in schedules:
routine = postgres.select_one("routines", {"id": schedule["routine_id"]})
if not routine:
logger.warning(f"Routine not found for schedule {schedule['id']}")
continue
now = _user_now_for(routine["user_uuid"])
current_time = now.strftime("%H:%M")
today = now.date()
if current_time != schedule.get("time"):
sched_time = schedule.get("time")
if current_time != sched_time:
continue
frequency = schedule.get("frequency", "weekly")
logger.info(f"Routine '{routine['name']}' time match at {current_time}")
frequency = schedule.get("frequency") or "weekly"
if frequency == "every_n_days":
start = schedule.get("start_date")
interval = schedule.get("interval_days")
@@ -149,13 +154,16 @@ def check_routine_reminders():
if (today - start_d).days < 0 or (
today - start_d
).days % interval != 0:
logger.info(f"Routine '{routine['name']}' skipped: not due today (every {interval} days from {start_d})")
continue
else:
logger.warning(f"Routine '{routine['name']}' skipped: every_n_days but missing start_date={start} or interval_days={interval}")
continue
else:
current_day = now.strftime("%a").lower()
days = schedule.get("days", [])
if current_day not in days:
logger.info(f"Routine '{routine['name']}' skipped: {current_day} not in {days}")
continue
user_settings = notifications.getNotificationSettings(routine["user_uuid"])
@@ -164,8 +172,11 @@ def check_routine_reminders():
notifications._sendToEnabledChannels(
user_settings, msg, user_uuid=routine["user_uuid"]
)
logger.info(f"Routine reminder sent for '{routine['name']}'")
else:
logger.warning(f"No notification settings for user {routine['user_uuid']}, skipping routine '{routine['name']}'")
except Exception as e:
logger.error(f"Error checking routine reminders: {e}")
logger.error(f"Error checking routine reminders: {e}", exc_info=True)
def check_refills():