Skip to content

Schedule

Source: core/schedule.gleam

The schedule module provides a shared cron expression parser with zero external dependencies. It lives in core/ so that both services/cron/ (the polling loop that executes scheduled jobs) and plugins/tools/cron/ (the chat-based cron management tool) can use it without cross-layer imports.

Types

  • CronJob -- alias (human-readable name), schedule (parsed CronSchedule), job_type (either ShellJob(command) or AgentJob(prompt))
  • CronSchedule -- five Field values: minute, hour, dom (day of month), month, dow (day of week)
  • Field -- Star (wildcard), Value(Int), Range(Int, Int), Step(Int) (e.g., */15), List(List(Field)) (comma-separated values)
  • CurrentTime -- minute, hour, dom, month, dow (the time to check against)
  • JobType -- ShellJob(command) runs a shell command; AgentJob(prompt) sends a prompt to the agent

Key Functions

  • parse_schedule(expr) -- parses a 5-field cron expression string (e.g., "0 9 * * 1-5") into a CronSchedule. Returns Result(CronSchedule, String).
  • cron_matches(schedule, now) -- checks whether a parsed CronSchedule matches a CurrentTime. Returns Bool.

The parser supports the standard cron field syntax: wildcards (*), exact values, ranges (1-5), steps (*/15), and comma-separated lists. Each of the 5 fields is parsed independently and combined into a single CronSchedule.

Usage

  • services/cron/ loads enabled cron jobs from the CronStore, parses schedules, and polls cron_matches() each minute to decide which jobs to fire.
  • plugins/tools/cron/ uses parse_schedule() to validate user-provided cron expressions when creating or editing cron jobs via chat.
  • Config -- Cron configuration loaded from TOML
  • Behaviours -- CronStore behaviour for persistence

Built with Gleam on the BEAM/Erlang VM.