v1.2.1

Scheduler API

Last updated


This page lists the core package API for creating, starting, and stopping a scheduler.
  1. 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


  1. type Config struct {
  2. Location *time.Location
  3. }

FieldDescription
LocationSchedule timezone; time.Local when nil

New


  1. 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


  1. 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


  1. 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.
  1. ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
  2. defer cancel()
  3. select {
  4. case <-c.Stop().Done():
  5. case <-ctx.Done():
  6. log.Println("shutdown timeout")
  7. }

See Task API for registering tasks and Dependency API for prerequisite types.
中文