Skip to content

[BACKEND] - Implement a scheduled job system to send email reminders #49

Description

@Gerson2102

📘 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

  1. Extend User Model

    • Add lastLoginAt and lastActivityAt fields to User schema
    • Update authentication controller to track login activity
  2. Create Notification Service

    • Create src/services/notification.service.ts
    • Implement methods to identify inactive users
    • Create reminder email templates and sending logic
  3. Install CRON Package

    • Add node-cron package for scheduled job management
    • Configure job scheduling in application startup
  4. Create Scheduled Job

    • Create src/jobs/userReminder.job.ts
    • Implement daily/weekly check for inactive users
    • Send different reminder types based on inactivity period
  5. Extend Email Service

    • Add reminder email templates to EmailNotifier
    • Create personalized reminder messages
    • Support different reminder types (7-day, 30-day, etc.)
  6. 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 ZohoMailer and EmailNotifier infrastructure
  • 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();
});

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions