Files
KeepItGoingServer/config/celery.py
T
Keith SmithandClaude Sonnet 5 5359bf243a Add per-task reminder notifications: before due, due now, and overdue
Only proactive notification was the once-a-day 6-7AM digest. Wires up
the previously-unused User.default_reminder_minutes profile setting
and ScheduledReminder model (Gitea #8) to send timely per-task alerts:

- Task.reschedule_reminders(), hooked into Task.save() via a dirty-check
  against due_date/due_time/reminder_at/status/is_deleted, (re)creates up
  to 3 ScheduledReminder rows per active due task: a "before due" reminder
  (from reminder_at if set, else default_reminder_minutes before due), a
  "due now" notification, and an "overdue" notification (mirroring
  is_overdue's day-after rule for date-only due tasks). Hooking into
  save() means every call site - web views, the API, and sync - picks
  this up automatically.
- New Celery task send_scheduled_reminders (beat schedule: every 5 min)
  sends due reminders via whichever of email/push the user has enabled,
  reusing the existing per-user channel toggles, and logs them to the
  Notification table.
- 14 new tests covering the scheduling math, due-date-change/completion/
  deletion cleanup, and the sending task's channel and timing behavior.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-05 09:46:12 -06:00

43 lines
1.1 KiB
Python

"""
Celery configuration for KeepItGoing.
"""
import logging
import os
from celery import Celery
from celery.schedules import crontab
logger = logging.getLogger(__name__)
# Set the default Django settings module
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
app = Celery('keepitgoing')
# Load config from Django settings
app.config_from_object('django.conf:settings', namespace='CELERY')
# Auto-discover tasks in all installed apps
app.autodiscover_tasks()
# Celery Beat schedule for periodic tasks
app.conf.beat_schedule = {
'send-daily-task-email': {
'task': 'notifications.tasks.send_daily_task_email',
'schedule': crontab(minute=0), # Every hour on the hour
},
'process-recurring-tasks': {
'task': 'notifications.tasks.process_recurring_tasks',
'schedule': crontab(hour=0, minute=0), # Daily at midnight
},
'send-scheduled-reminders': {
'task': 'notifications.tasks.send_scheduled_reminders',
'schedule': crontab(minute='*/5'), # Every 5 minutes - these are time-sensitive
},
}
@app.task(bind=True)
def debug_task(self):
logger.debug(f'Request: {self.request!r}')