Scheduler
For a short summary of a Scheduler, see Reventless Components Overview.
This component follows the Reventless Component Structure Pattern, using separate files for interface definitions (Scheduler.res), builder logic (Scheduler_Builder.res), and adapter interface (Scheduler_Adapter.res).
Overview
The Scheduler component provides time-based command publishing capabilities, enabling scheduled workflows, periodic tasks, and cron-like event generation. It allows applications to create and manage schedules dynamically at runtime.
Purpose and Responsibilities
- Responsibility: Manage time-based event scheduling and command publishing
- In: Schedule definitions with timing patterns and payloads
- Out: Scheduled events/commands published to configured targets
Schedule Specification
The Scheduler uses a flexible schedule specification that supports various timing patterns:
Schedule Types
Schedule.time has one constructor per shape of a time:
type interval = Minutes(int) | Hours(int) | Days(int) | Weeks(int)
type weekday = Mon | Tue | Wed | Thu | Fri | Sat | Sun
type calendar =
| Daily({hour: hour, minute: minute})
| Weekly({days: array<weekday>, hour: hour, minute: minute})
| Monthly({day: day, hour: hour, minute: minute, every?: int}) // every: 3 is quarterly
| Yearly({month: month, day: day, hour: hour, minute: minute})
type period = Minutes(int) | Hours(int) | Days(int) | Weeks(int) | Months(int) | Years(int)
type localTime = {year: year, month: month, day: day, hour: hour, minute: minute}
type moment = At(localTime) | After(period)
type zone = string // an IANA name such as "Europe/Berlin"; absent means UTC
type time =
| Every(interval) // a fixed length, from the previous firing
| Calendar({calendar: calendar, zone?: zone}) // a wall-clock time that recurs
| Once({moment: moment, zone?: zone}) // a single moment
type schedule = {
name: string, // Unique identifier for the schedule
time: time, // When it fires
payload: string, // Data to publish when the schedule fires
}
- Daylight saving. A calendar time in the hour daylight saving skips does not fire that day; one in the repeated hour fires once. Both platforms follow this rule.
- Months and years are not intervals. Every month is a calendar time (
Monthly). AMonthlyday that a month lacks (the 31st) is skipped in that month. Afteris counted from the moment the schedule is created, by the calendar of its zone: a month from 31 January is the last day of February. A once-only time already past never fires.- An invalid time is refused when the schedule is created: an unknown zone, an hour of 24 or a weekly time without days.
Example Schedule Definitions
// Daily report generation at 09:00 in Berlin
let dailyReport = {
Reventless.Schedule.name: "daily-report",
time: Calendar({calendar: Daily({hour: 9, minute: 0}), zone: "Europe/Berlin"}),
payload: `{"type": "GenerateReport", "reportType": "daily"}`,
}
// Cleanup task every 6 hours
let cleanupTask = {
name: "cleanup-task",
time: Every(Hours(6)),
payload: `{"type": "CleanupTempFiles"}`,
}
// One-time reminder
let reminder = {
name: "meeting-reminder",
time: Once({moment: At({year: 2026, month: 12, day: 25, hour: 14, minute: 30})}),
payload: `{"type": "SendReminder", "meetingId": "abc123"}`,
}
Usage Patterns
Basic Scheduler Setup
// In your plugin definition
module MyPlugin = {
let scheduler = Reventless.Scheduler.make()
// Access scheduler operations at runtime
let scheduleOperations = scheduler.operations
}
Runtime Schedule Management
// Create a schedule dynamically
let createDailyBackup = async () => {
let schedule = {
Reventless.Schedule.name: "daily-backup",
time: Calendar({calendar: Daily({hour: 2, minute: 0})}), // 02:00 UTC daily
payload: `{"type": "StartBackup", "target": "database"}`,
}
await scheduler.operations.createSchedule([], schedule)
}
// Remove a schedule when no longer needed
let removeSchedule = async (scheduleName) => {
await scheduler.operations.deleteSchedule([], scheduleName)
}
At run time
The Scheduler component operates through two main runtime operations:
Schedule Creation Flow
Schedule Deletion Flow
Integration Points
The Scheduler integrates with other Reventless components to enable time-based workflows:
Common Integration Patterns
Integration with Command Topics
// Scheduler publishes to CommandTopic for aggregate processing
let scheduleAggregateCommand = {
name: "process-orders",
time: Every(Hours(1)),
payload: `{"aggregateId": "order-processor", "command": "ProcessPendingOrders"}`,
}
Integration with Event Topics
// Scheduler can trigger event publication for system monitoring
let healthCheckSchedule = {
name: "health-check",
time: Every(Minutes(5)),
payload: `{"type": "HealthCheckEvent", "timestamp": "${Date.now()}"}`,
}
Common Patterns
Periodic Data Processing
// Process batch data every hour
let batchProcessor = {
name: "batch-processor",
time: Every(Hours(1)),
payload: `{"type": "ProcessBatch", "batchSize": 1000}`,
}
Business Hours Scheduling
// Send daily reports only on weekdays
let businessReport = {
name: "business-report",
time: Calendar({calendar: Weekly({days: [Mon, Tue, Wed, Thu, Fri], hour: 17, minute: 0})}),
payload: `{"type": "GenerateBusinessReport"}`,
}
Cleanup and Maintenance
// Daily cleanup at midnight
let dailyCleanup = {
name: "daily-cleanup",
time: Calendar({calendar: Daily({hour: 0, minute: 0})}),
payload: `{"type": "CleanupExpiredData"}`,
}
Dynamic User Schedules
// Create user-specific reminder schedules
let createUserReminder = async (userId, reminderTime: Reventless.Schedule.localTime, zone) => {
let schedule = {
name: `user-reminder-${userId}`,
time: Once({moment: At(reminderTime), zone}),
payload: `{"type": "UserReminder", "userId": "${userId}"}`,
}
await scheduler.operations.createSchedule([], schedule)
}
Pulumi
The Scheduler component is deployed as infrastructure that creates the IAM role EventBridge Scheduler delivers with, and the schedule group the platform's schedules go into. The schedules themselves are created at run time through the component's operations.
// Deployment creates the scheduler role and its schedule group
let scheduler = Reventless.Scheduler.make(~opts=pulumiOpts)
// Runtime operations use the deployed role to manage schedules
let operations = scheduler.outputs.resource
AWS Implementation
For detailed AWS-specific implementation including EventBridge integration, IAM role configuration, and runtime operations, see ScheduledPublisher → EventBridge Scheduler.