Lightweight Go task scheduler with cron syntax, task dependency chains, and failure strategy control.
go get github.com/pardnchiu/go-scheduler· Documentation
Supports standard five-field cron expressions and preset descriptors like @every and @daily. A min-heap sorts trigger times so the next due task is woken with minimal overhead. Tasks can be added or removed dynamically while the scheduler is running, with no restart required.
Tasks can declare dependencies on other tasks, and the scheduler automatically blocks execution until prerequisites complete. Two failure strategies are provided: Skip ignores the failure and proceeds, while Stop aborts the entire dependency chain. Each dependency accepts an independent timeout to prevent a single stalled task from blocking the whole schedule.
Each task runs in its own goroutine, with mutex and channel coordination ensuring consistent state. Panics are automatically recovered so one failing task never crashes the scheduler. Context-based timeouts trigger an onDelay callback, giving callers a hook for cleanup logic.
graph TB
subgraph Scheduler
C[Cron Engine]
H[Min-Heap]
end
subgraph Dependencies
DM[Depend Manager]
W[Worker Pool]
end
C -->|schedule trigger| H
H -->|due task| C
C -->|has deps| DM
C -->|no deps| G[Goroutine Exec]
DM -->|check complete| W
W -->|deps satisfied| G
G -->|report result| DM
go-scheduler/
├── instance.go # Scheduler creation, start, stop, and task execution
├── add.go # Task addition and argument parsing
├── remove.go # Task removal
├── task.go # Task listing and heap implementation
├── schedule.go # Cron expression and descriptor parsing
├── type.go # Type definitions and constants
├── depend.go # Dependency worker pool and task execution
├── dependManager.go # Dependency checking, waiting, and state updates
├── cron_test.go # Unit tests and benchmarks
├── go.mod
└── LICENSE
This project is licensed under the MIT LICENSE.
©️ 2025 邱敬幃 Pardn Chiu