Scheduling

Schedo.dev provides flexible scheduling options for running jobs, supporting cron expressions

Cron Expressions

Jobs can be scheduled using standard cron expressions:

schedo.defineJob(
  'daily-backup',
  '0 0 * * *',    // Run at midnight every day
  async (ctx) => {
    // Job implementation
  }
);

Cron Format

Cron expressions consist of five fields:

┌───────────── minute (0 - 59)
│ ┌───────────── hour (0 - 23)
│ │ ┌───────────── day of month (1 - 31)
│ │ │ ┌───────────── month (1 - 12)
│ │ │ │ ┌───────────── day of week (0 - 6) (Sunday to Saturday)
│ │ │ │ │
* * * * *

Common Patterns

// Every minute
'* * * * *'

// Every 15 minutes
'*/15 * * * *'

// Every hour
'0 * * * *'

// Every day at midnight
'0 0 * * *'

// Every Monday at 9:00 AM
'0 9 * * 1'

// Every month on the 1st at midnight
'0 0 1 * *'

Schedule Validation

Schedo.dev validates both cron expressions and intervals:

// Invalid cron expression
schedo.defineJob(
  'invalid-job',
  '0 24 * * *',    // 24 is invalid hour
  async (ctx) => {
    // Never runs - throws error during definition
  }
);

Best Practices

  1. Consider Business Hours

    // Run during business hours (9 AM - 5 PM on weekdays)
    '0 9-17 * * 1-5'
    
  2. Stagger High-Load Jobs

    // Instead of all jobs at midnight
    '0 0 * * *'     // Job A
    '5 0 * * *'     // Job B
    '10 0 * * *'    // Job C
    

Next Steps