-
Notifications
You must be signed in to change notification settings - Fork 30
[BACKEND] - Implement a scheduled job system to send email reminders #49
Copy link
Copy link
Open
Labels
Description
📘 Issue Description
Implement a scheduled job system to send email reminders to inactive users who haven't logged in or engaged with the platform for a specified period. This will help re-engage users and improve platform retention through automated reminder campaigns.
🔍 Steps
-
Extend User Model
- Add
lastLoginAtandlastActivityAtfields to User schema - Update authentication controller to track login activity
- Add
-
Create Notification Service
- Create
src/services/notification.service.ts - Implement methods to identify inactive users
- Create reminder email templates and sending logic
- Create
-
Install CRON Package
- Add
node-cronpackage for scheduled job management - Configure job scheduling in application startup
- Add
-
Create Scheduled Job
- Create
src/jobs/userReminder.job.ts - Implement daily/weekly check for inactive users
- Send different reminder types based on inactivity period
- Create
-
Extend Email Service
- Add reminder email templates to EmailNotifier
- Create personalized reminder messages
- Support different reminder types (7-day, 30-day, etc.)
-
Environment Configuration
- Add reminder settings to environment variables
- Configure inactivity thresholds and reminder intervals
✅ Acceptance Criteria
- Activity Tracking: User login and activity timestamps are properly tracked
- Scheduled Jobs: CRON jobs run automatically to check for inactive users
- Email Reminders: Automated emails sent to inactive users with proper templates
- Configurable Thresholds: Inactivity periods and reminder intervals are configurable
- Job Logging: Proper logging for scheduled job execution and email sending
- Error Handling: Failed email attempts are handled gracefully with retry logic
Reminder Schedule
| Inactivity Period | Reminder Type | Frequency |
|---|---|---|
| 7 days | Gentle reminder | Once |
| 14 days | Re-engagement | Once |
| 30 days | Special offer/content | Once |
| 60 days | Final reminder | Once |
Database Schema Changes
-- Add to User table
ALTER TABLE users ADD COLUMN last_login_at TIMESTAMP;
ALTER TABLE users ADD COLUMN last_activity_at TIMESTAMP;🌎 References
- Existing email service in
src/utils/service/emailNotifier.ts - Current user model in
prisma/schema.prisma - Authentication patterns in
src/controllers/auth.controller.ts - node-cron documentation
📜 Additional Notes
Implementation Approach
- Leverage existing
ZohoMailerandEmailNotifierinfrastructure - Run CRON job daily at off-peak hours (e.g., 2 AM UTC)
- Track reminder history to avoid duplicate emails
- Support both development and production scheduling
Email Templates
7-day reminder: "We miss you! Come back and practice your English skills"
30-day reminder: "Special learning resources waiting for you"
60-day reminder: "Don't lose your progress - continue your English journey"
Job Configuration
// Daily at 2 AM UTC
cron.schedule('0 2 * * *', async () => {
await UserReminderJob.checkInactiveUsers();
});Reactions are currently unavailable