Skip to main content
The Cron module enables scheduled execution of functions using cron expressions. Perfect for periodic tasks like cleanup jobs, reports, and background processing.

Configuration

Configure the Cron module in config.yaml:
config.yaml

Available Adapters

File-based or in-memory storage:

Creating Scheduled Functions

Define cron triggers with standard cron expressions:
index.ts

Cron Expression Format

Cron expressions use the standard 5-field format:

Common Cron Patterns

Input Format

Cron-triggered functions receive timing information:
Input structure:

Conditional Execution

Use conditions to control whether a scheduled task should run:

Example Use Cases

Daily Database Cleanup

Hourly Data Sync

Weekly Reports

Periodic Health Checks

Timezone Considerations

Cron expressions run in the server’s timezone. For UTC-based scheduling, ensure your server timezone is set to UTC or convert times accordingly.
Example for timezone-aware scheduling:

Best Practices

  1. Idempotent Functions: Make sure cron functions can safely run multiple times
  2. Error Handling: Always handle errors gracefully
  3. Monitoring: Log execution times and results
  4. Avoid Overlaps: Ensure tasks complete before next scheduled run
  5. Use Conditions: Filter execution based on business rules

Debugging Cron Jobs

View registered cron jobs in logs:

Source Code Reference

  • Module: src/modules/cron/cron.rs:29
  • Trigger registration: src/modules/cron/cron.rs:88
  • Adapters: src/modules/cron/adapters/