Skip to main content

Overview

Cron expressions define when recurring jobs should execute. Cuey uses the standard 5-field cron format.

Cron Format

Cron expressions consist of 5 fields separated by spaces:
┌───────────── minute (0 - 59)
│ ┌───────────── hour (0 - 23)
│ │ ┌───────────── day of month (1 - 31)
│ │ │ ┌───────────── month (1 - 12)
│ │ │ │ ┌───────────── day of week (0 - 6) (Sunday to Saturday)
│ │ │ │ │
* * * * *

Field Values

FieldValuesSpecial Characters
Minute0-59* , - /
Hour0-23* , - /
Day of Month1-31* , - /
Month1-12* , - /
Day of Week0-6 (0=Sunday)* , - /

Special Characters

  • * - Matches any value
  • , - Value list separator (e.g., 1,3,5)
  • - - Range (e.g., 1-5)
  • / - Step values (e.g., */15)

Common Examples

Every Minute

* * * * *

Every Hour

0 * * * *

Every Day at Midnight

0 0 * * *

Every Day at 9 AM

0 9 * * *

Every Monday at 9 AM

0 9 * * 1

Every Weekday at 9 AM

0 9 * * 1-5

Every 15 Minutes

*/15 * * * *

Every 30 Minutes

*/30 * * * *

Every Hour on the Hour

0 * * * *

First Day of Every Month at Midnight

0 0 1 * *

Every Monday, Wednesday, Friday at 9 AM

0 9 * * 1,3,5

Every Day at 9 AM and 5 PM

0 9,17 * * *

Timezone Support

Cron expressions can be combined with timezones to schedule jobs in specific time zones. When creating a cron job, you can specify a timezone (e.g., America/New_York, Europe/London). If no timezone is specified, UTC is used.

Example: Daily Report in Different Timezones

  • Daily report at 9 AM EST: 0 9 * * * with timezone America/New_York
  • Daily report at 9 AM PST: 0 9 * * * with timezone America/Los_Angeles
  • Daily report at 9 AM UTC: 0 9 * * * with no timezone (defaults to UTC)

Advanced Patterns

Every 5 Minutes During Business Hours (9 AM - 5 PM, Weekdays)

*/5 9-17 * * 1-5

Every Hour During Night Hours (10 PM - 6 AM)

0 22-23,0-6 * * *

Twice Daily (9 AM and 6 PM)

0 9,18 * * *

Every 10 Minutes on Weekdays

*/10 * * * 1-5

First Monday of Every Month

This requires more complex logic - consider using scheduled events instead of cron jobs for this pattern.

Best Practices

Use Specific Times

  • Good: 0 9 * * * - Specific time (9 AM sharp)
  • Avoid: * * * * * - Every minute (unless necessary)

Consider Timezones

  • Good: Specify timezone for user-facing schedules (e.g., America/New_York for business hours)
  • Good: Use UTC for system-level jobs (omit timezone or set to null)

Document Complex Expressions

When using complex cron expressions, document what they represent in comments or descriptions:
  • 0 9 * * 1-5 - Weekdays at 9 AM
  • */5 9-17 * * 1-5 - Every 5 minutes during business hours (9 AM - 5 PM, weekdays)

Common Use Cases

Health Checks

*/5 * * * *  // Every 5 minutes

Daily Reports

0 9 * * *  // Every day at 9 AM

Weekly Summaries

0 9 * * 1  // Every Monday at 9 AM

Monthly Tasks

0 0 1 * *  // First day of month at midnight

Testing Cron Expressions

You can test cron expressions using online tools or validate them when creating cron jobs. Invalid cron expressions will be rejected with a validation error.