Jun 29 - Implement auto reminder 45 min before user's shift end if not finish checking websites

This commit is contained in:
2026-06-29 17:03:07 -04:00
parent 176e19213c
commit 56a256633b
4 changed files with 59 additions and 7 deletions
+7 -3
View File
@@ -118,7 +118,7 @@ def edit(shift_id):
return redirect(url_for("admin_shifts.shifts_list"))
REMINDER_WINDOW_MIN = 40
REMINDER_WINDOW_MIN = 45
def _fmt_time(t) -> str:
@@ -144,6 +144,11 @@ def do_send_incomplete_reminders(triggered_by_user_id=None) -> dict:
skipped += 1
continue
# Atomically claim this reminder slot before sending.
# If another worker already claimed it (rowcount == 0), skip to avoid duplicates.
if not record_shift_reminder(row["user_id"], row["shift_id"]):
continue
end_str = _fmt_time(row["end_time"])
site_lines = "\n".join(
f"{s['name']}{s['url']}" for s in row["unchecked_sites"]
@@ -163,7 +168,6 @@ def do_send_incomplete_reminders(triggered_by_user_id=None) -> dict:
f"Action required — complete your shift checks by {end_str}",
body,
)
record_shift_reminder(row["user_id"], row["shift_id"])
log_action(
triggered_by_user_id, "SHIFT_INCOMPLETE_REMINDER", "shifts", row["shift_id"],
f"Reminder sent to {row['username']} ({row['email']}): "
@@ -180,7 +184,7 @@ def do_send_incomplete_reminders(triggered_by_user_id=None) -> dict:
@admin_shifts_bp.route("/send-incomplete-reminders", methods=["POST"])
@admin_required
def send_incomplete_reminders():
"""Manual trigger: email staff with incomplete checks in shifts ending within 40 min."""
"""Manual trigger: email staff with incomplete checks in shifts ending within 45 min."""
result = do_send_incomplete_reminders(triggered_by_user_id=session["user"]["id"])
if result["total"] == 0: