Scheduler API
Last updated
This page lists the core package API for creating, starting, and stopping a scheduler.
import "github.com/pardnchiu/go-scheduler/core"
New returns the unexported *cron; its exported methods are callable directly, and := infers the type when storing it.
Config
type Config struct {
Location *time.Location
}
| Field | Description |
|---|---|
Location |
Schedule timezone; time.Local when nil |
New
func New(c Config) (*cron, error)
Creates a scheduler and initializes the min-heap, parser, dependency subsystem, and logger. The current implementation always returns a nil error.
Start
func (c *cron) Start()
Starts the dependency worker pool and event loop and computes next fire times for registered tasks. No-op when already running.
Stop
func (c *cron) Stop() context.Context
Stops the event loop, waits for dependency workers to exit, and returns a context cancelled after in-flight tasks without dependencies finish.
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
select {
case <-c.Stop().Done():
case <-ctx.Done():
log.Println("shutdown timeout")
}
See Task API for registering tasks and Dependency API for prerequisite types.