go-scheduler
Job scheduler supporting standard cron expressions, custom descriptors, intervals, and task dependencies
About go-scheduler
[!NOTE] This README was generated by SKILL, get the ZH version from here.
go-scheduler
Lightweight Go task scheduler with cron syntax, task dependency chains, and failure strategy control.
Table of Contents
Features
go get github.com/pardnchiu/go-scheduler· Documentation
Cron Scheduling with Live Dispatch
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.
Task Dependency Chains with Failure Strategies
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.
Concurrency-Safe Execution with Panic Recovery
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.
Architecture
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
File Structure
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
License
This project is licensed under the MIT LICENSE.
Author
Stars
©️ 2025 邱敬幃 Pardn Chiu
Frequently Asked Questions
What is go-scheduler?
go-scheduler is a Job Scheduler library for the Go programming language. Job scheduler supporting standard cron expressions, custom descriptors, intervals, and task dependencies
How do I install go-scheduler?
Install go-scheduler with the Go module system using `go get pardnchiu/go-scheduler`. Check the repository for the current installation instructions.
What category does go-scheduler belong to?
go-scheduler is listed under Job Scheduler, specifically Job Scheduler.