How do I run health checks with a cron job?
Schedule every 5 minutes (cron.schedule('*/5 * * * *', ...)). Ping the database (mongoose.connection.db.admin().ping()), ping Redis if used, and update a health status key in Redis with a 5-minute TTL. Send an alert if any check fails.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Common Cron Job Use Cases in Node.js Cleanup, Notifications, and Reports
Data cleanup (delete old tokens, unverified users, expired records), email notifications (daily digests, renewal reminders), report generation (weekly analytics), database backups (daily mongodump to S3), cache warming, log rotation, and health checks (verify database and Redis connectivity).
Schedule a daily task at midnight (cron.schedule('0 0 * * *', ...)). Use MongoDB queries to delete documents older than a threshold: await User.deleteMany({ createdAt: { $lt: thirtyDaysAgo } }). Clean up expired tokens, unverified users, and old connection requests.
Schedule at 9 AM (cron.schedule('0 9 * * *', ...)). Find users with pending connection requests from the last 24 hours. For each user, send a digest email with their pending requests. Check emailBounced and emailComplained flags before sending.
Still have questions?
Browse all our FAQs or reach out to our support team
