Getting Started
Install go-scheduler and run your first scheduled task.
Prerequisites
- Go 1.23 or higher
Installation
Using go get
go get github.com/pardnchiu/go-scheduler
From Source
git clone https://github.com/pardnchiu/go-scheduler.git
cd go-scheduler
go build ./...
Quick Start
Create a scheduler, add a task, and start it:
package main
import (
"fmt"
"time"
"github.com/pardnchiu/go-scheduler/core"
)
func main() {
c, err := core.New(core.Config{})
if err != nil {
panic(err)
}
id, err := c.Add("@every 30s", func() {
fmt.Println("hello", time.Now())
}, "heartbeat")
if err != nil {
panic(err)
}
fmt.Println("task id:", id)
c.Start()
defer func() {
ctx := c.Stop()
<-ctx.Done()
}()
time.Sleep(2 * time.Minute)
}
Custom Timezone
Pass a *time.Location via Config.Location. When nil, the scheduler uses time.Local.
loc, err := time.LoadLocation("Asia/Taipei")
if err != nil {
panic(err)
}
c, err := core.New(core.Config{
Location: loc,
})
if err != nil {
panic(err)
}
Next Steps
- Architecture — system modules and data flow
- Core Concepts — tasks, schedules, dependencies, timeouts
- API Reference — Config, New, Add, Remove, List, Wait