Cron Jobs

CRON_JOBS.md

Cron Jobs

All 35 scheduled jobs are declared in vercel.json and run as GET requests to /api/cron/<name>. Every endpoint requires Authorization: Bearer <CRON_SECRET> when called by an external scheduler, or the Vercel-platform x-vercel-cron: 1 header when invoked by Vercel Cron infrastructure.

Auth reminder

Set CRON_SECRET in your environment. When calling manually (staging tests, curl):

curl -H "Authorization: Bearer $CRON_SECRET" https://your-domain.com/api/cron/<name>

Schedule reference

JobSchedule (UTC)Frequency
reminders0 9 * * *Daily 09:00
queue-optimization*/15 * * * *Every 15 min
smart-assignment0 */1 * * *Every hour
waitlist-management5,20,35,50 * * * *Every 15 min (offset 5)
no-show-handling10,40 * * * *Every 30 min
medication-reminders0 8,12,16,20 * * *Daily 08/12/16/20
daily-reports0 23 * * *Daily 23:00
backup0 2 * * *Daily 02:00
payment-reminders0 10 * * *Daily 10:00
inventory-alerts0 8 * * *Daily 08:00
inventory-reordering15 9 * * *Daily 09:15
prescription-refills0 9 * * *Daily 09:00
prescription-expiry-warnings5 8 * * *Daily 08:05
insurance-verification10 8 * * *Daily 08:10
followup-scheduling0 11 * * *Daily 11:00
recurring-appointments0 13 * * *Daily 13:00
auto-cancellation-policies30 10 * * *Daily 10:30
health-reminders0 12 * * *Daily 12:00
expiry-monitoring0 7 * * *Daily 07:00
document-expiry-tracking30 9 * * *Daily 09:30
end-of-day-cleanup0 10 * * *Daily 10:00
birthday-greetings0 0 * * *Daily 00:00 (midnight)
feedback-collection0 10 * * *Daily 10:00
weekly-reports0 8 * * 1Monday 08:00
monthly-reports0 8 1 * *1st of month 08:00
weekly-staff-performance0 9 * * 1Monday 09:00
monthly-staff-performance0 9 1 * *1st of month 09:00
trial-expiration0 6 * * *Daily 06:00
usage-alerts0 9 * * *Daily 09:00
data-retention0 2 * * 0Sunday 02:00
lab-notifications*/30 * * * *Every 30 min
membership-expiry0 8 * * *Daily 08:00
referral-followup0 9 * * *Daily 09:00
visit-followup0 8 * * *Daily 08:00
patient-reengagement0 10 * * 1Monday 10:00

Job descriptions

Patient Care

JobWhat it does
remindersSends appointment reminders (SMS/email) for upcoming visits
medication-remindersNotifies patients of scheduled medication times
health-remindersSends general health check-up reminders to eligible patients
prescription-refillsAlerts patients whose prescriptions are due for refill
prescription-expiry-warningsWarns patients and staff of prescriptions expiring soon
followup-schedulingCreates follow-up appointment tasks after completed visits
visit-followupSends post-visit follow-up messages to patients
birthday-greetingsSends birthday messages to patients
feedback-collectionRequests satisfaction feedback after appointments
patient-reengagementIdentifies and re-engages inactive patients
lab-notificationsNotifies patients and doctors when lab results are ready

Appointments & Queue

JobWhat it does
queue-optimizationRebalances the live patient queue for efficiency
smart-assignmentAuto-assigns patients to available doctors based on load
waitlist-managementPromotes waitlisted patients when slots open
no-show-handlingMarks patients as no-show and frees appointment slots
recurring-appointmentsGenerates next occurrence for recurring appointment templates
auto-cancellation-policiesCancels appointments that breach cancellation policy rules

Clinical & Documents

JobWhat it does
insurance-verificationBatch-verifies insurance eligibility for upcoming appointments
expiry-monitoringMonitors staff licences, certifications, and supply expiry dates
document-expiry-trackingFlags patient and clinic documents nearing expiry
referral-followupFollows up on open referrals that haven't been acknowledged

Inventory & Finance

JobWhat it does
inventory-alertsAlerts staff when stock levels fall below minimum threshold
inventory-reorderingTriggers automatic reorder requests for low-stock items
payment-remindersSends overdue invoice reminders to patients
membership-expiryNotifies patients whose membership plans are expiring

Reporting & Analytics

JobWhat it does
daily-reportsGenerates and emails daily clinic summary reports
weekly-reportsGenerates and emails weekly performance reports
monthly-reportsGenerates and emails monthly analytics reports
weekly-staff-performanceCompiles weekly staff productivity metrics
monthly-staff-performanceCompiles monthly staff performance summaries
usage-alertsAlerts tenant admins when subscription usage limits are near

System

JobWhat it does
trial-expirationProcesses expired trial tenants and sends expiry warnings
data-retentionApplies configured data-retention policies (purge/anonymise old records)
backupTriggers a database backup and logs the result
end-of-day-cleanupCleans up transient records, expired sessions, and temp files

Monitoring

Add an external uptime check (e.g. Better Uptime, UptimeRobot) pointing to /api/health/live. For individual job monitoring, call each endpoint manually in staging after deploy and verify the success: true response.

Cron jobs that fail silently (return 200 but log errors) are caught by lib/logger.ts — wire up SENTRY_DSN to surface them in error tracking.