Schedule processing
Schedule processing turns stored project schedules into timed starts for template tasks or workflow runs. The SchedulePool keeps eligible schedules ready in the configured time zone, while the ScheduleRunner checks each due schedule and hands valid work to the task or workflow system.
Schedule records
Schedule records join a time rule to one project target. A target is either a template or a workflow, and a schedule can also carry task parameters for a template run (home/…/schedule.go• L10-35).
The system supports two time forms:
| Form | Time value | Repeat behavior | Past-due behavior |
|---|---|---|---|
| Cron | CronFormat | Repeats from the cron rule | The pool does not add an empty or invalid time rule |
| Run-at | RunAt | Runs once | The record is deleted when DeleteAfterRun is set. Otherwise it is disabled |
The database treats an empty type as cron when it stores a new or updated record. It also rejects a schedule without a valid target and keeps workflow schedules free of separate task parameters because the workflow root owns its inputs (home/…/schedule.go• L14-40, home/…/schedule.go• L78-120).
SchedulePool lifecycle
The SchedulePool is the time-based boundary between shared schedule storage and local execution. It loads records with a time value, removes its old entries, and rebuilds the active in-memory set in the configured schedule time zone (home/…/schedule.go• L208-211, home/…/SchedulePool.go• L337-439).
This flow shows how stored schedule state becomes executable work.
flowchart LR
A[Stored schedule] --> B[Pool refresh]
B --> C{Time form}
C -->|Cron| D[Recurring entry]
C -->|Run-at| E[One-time entry]
D --> F[ScheduleRunner at due time]
E --> F
F --> G{Target}
G -->|Template| H[Waiting task]
G -->|Workflow| I[Workflow run]
Refresh is the point where database changes reach the local timer. A schedule update or deletion therefore takes effect after the pool reloads its records. The pool also refreshes after a run-at attempt so the one-time entry is removed when its stored record is disabled or deleted (home/…/SchedulePool.go• L346-439, home/…/SchedulePool.go• L117-175).
Each node keeps its own timer entries. When a deduplicator is configured, the runner takes an execution lock before it starts the target. A node that does not get the lock skips the occurrence, and a run-at schedule causes that node to refresh so it can drop a stale local entry (home/…/SchedulePool.go• L149-161, home/…/SchedulePool.go• L266-308).
References: home/…/SchedulePool.go• L266-439 home/…/schedule.go• L208-211
Schedule execution
ScheduleRunner is the handoff from a due time to project work. It reloads the schedule from storage, applies the optional repository commit check, takes the cluster execution lock when present, and then starts the selected target (home/…/SchedulePool.go• L117-175).
Template schedules create a task with the schedule's parameters when they exist. The task keeps the schedule ID and enters through the normal task creation path. Workflow schedules instead start the linked workflow with the schedule ID and the workflow's own default inputs (home/…/SchedulePool.go• L178-264).
Repository-backed schedules add a content-change gate. The runner stores the latest remote commit and creates work only when that commit differs from the saved value. An unchanged commit therefore produces no task or workflow run for that occurrence (home/…/SchedulePool.go• L65-114).
The scheduler does not perform the task automation itself. It decides when work may start and passes that work to the task or workflow system, which owns the later execution stages.
References: home/…/SchedulePool.go• L65-264 home/…/schedule.go• L68-75
One-time schedule handling
Run-at schedules represent one future occurrence. The pool does not add a record whose time has arrived or passed. It deletes such a record when configured to do so, or disables it when the record should remain for history (home/…/SchedulePool.go• L380-413).
After a future run-at entry fires, the runner refreshes the pool. This links the one-time timer behavior to the database state and prevents the same record from remaining executable on that node (home/…/SchedulePool.go• L31-46, home/…/SchedulePool.go• L170-175).
References: home/…/SchedulePool.go• L31-46 home/…/SchedulePool.go• L380-413
Schedule state changes
Schedule persistence keeps the schedule and its optional task parameters as one ownership unit. Creation and update validate the target first, save or replace the parameters, and link them from the schedule. Removing parameters during an update deletes the old parameter record (home/…/schedule.go• L14-65, home/…/schedule.go• L78-159).
An update clears the saved repository commit hash. The next due run must therefore check the repository again instead of reusing a result from the old schedule definition. Deleting a schedule also deletes its linked task parameters (home/…/schedule.go• L122-157, home/…/schedule.go• L186-205).
References: home/…/schedule.go• L14-65 home/…/schedule.go• L78-159 home/…/schedule.go• L186-205
Change checklist
When these files or sections are changed, remember to consider these:
- Keep target validation and workflow parameter ownership aligned between schedule storage and runner behavior.
- Keep run-at deactivation or deletion aligned with the refresh that removes its local timer entry.
- Keep the schedule ID attached to template tasks and workflow runs so history can identify the source schedule.
- Keep the execution lock immediately before target start when changing clustered scheduling behavior.
- Keep commit-hash reset aligned with schedule updates so changed repository-backed schedules can run again.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A schedule has no valid target | The scheduled work cannot start | Storage validates that the schedule points to a template or workflow |
| A run-at record has no future time | It does not create a late task | Refresh skips malformed records and deletes or disables past records |
| A cron record has no time rule | It is not added to the timer | Refresh skips an empty cron value and reports invalid entries |
| Two nodes reach one occurrence | Duplicate starts are possible without shared coordination | The configured deduplicator allows one node to proceed |
| A repository has no new commit | The occurrence creates no work | The runner compares the remote commit with the saved hash |
| Workflow support is unavailable | A workflow schedule logs an error and starts nothing | The runner requires both a workflow store and workflow service |
Key files
| File | Why to read it |
|---|---|
| home/…/SchedulePool.go | Main refresh, timing, deduplication, and target-start flow |
| home/…/schedule.go | Schedule storage, target validation, parameter ownership, and records loaded by the pool |
| home/…/SchedulePool_test.go | Core guarantees for one-time timing, clustered deduplication, and workflow starts |
| home/…/Schedule.go | Schedule target and time-rule model used by storage and execution |