v1.2.1

Configuration

Last updated


This page covers go-scheduler's scheduler settings, per-task options, and the runtime defaults for logging and the worker pool.

Scheduler Settings


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

FieldDefaultEffect
Locationtime.LocalTimezone used to compute the next fire time of cron expressions and descriptors

  1. loc, err := time.LoadLocation("Asia/Taipei")
  2. if err != nil {
  3. log.Fatal(err)
  4. }
  5. c, err := core.New(core.Config{Location: loc})
  6. if err != nil {
  7. log.Fatal(err)
  8. }
  9. if _, err := c.Add("30 9 * * 1-5", func() error {
  10. return sendReport()
  11. }, "weekday report"); err != nil {
  12. log.Fatal(err)
  13. }

30 9 * * 1-5 fires at 09:30 Monday to Friday in Asia/Taipei time.
The package reads no environment variables or configuration files.

Task Options


Add identifies variadic arguments by type, in any order:
  1. func (c *cron) Add(spec string, action interface{}, arg ...interface{}) (int64, error)

TypeSetsNotes
stringTask descriptionLogged by the dependency worker
time.DurationExecution limitNot a start delay; 0 means no limit
func()Timeout callbackCalled only when the execution limit is exceeded
[]core.WaitPrerequisitesAction must be func() error
[]int64Prerequisites (deprecated)Each ID becomes Wait{ID: id} with the Stop policy

When the same type is passed more than once, the last string / time.Duration / func() wins, while []core.Wait and []int64 accumulate.
  1. _, err := c.Add("*/10 * * * *", func() error {
  2. return syncInventory()
  3. }, "inventory sync", 2*time.Minute, func() {
  4. log.Println("inventory sync exceeded 2m")
  5. }, []core.Wait{
  6. {ID: authID, State: core.Stop},
  7. {ID: cacheID, State: core.Skip},
  8. })
  9. if err != nil {
  10. log.Fatal(err)
  11. }

Dependency Settings


FieldValueEffect
IDPrerequisite task IDDependent task fails when the ID does not exist
Statecore.Stop (default)Dependent task fails when the prerequisite fails
Statecore.SkipFailed prerequisite is ignored
DelayAnyCurrently not applied; the wait limit is fixed at 1 minute

Runtime Defaults


ItemValueSource
Loggersyslog (LOG_INFO|LOG_LOCAL0, tag goCron) in JSONcore/instance.go
Logger fallbackstderr text, Info levelWhen syslog cannot be opened
Dependency workersruntime.NumCPU(), or 2 when CPUs ≤ 2core/depend.go
Wait queue capacity1024core/depend.go
Dependency poll interval1mscore/dependManager.go
@every minimum interval30 secondscore/schedule.go

None of these values can be changed by callers.
See Task Dependencies and Timeouts for runtime behavior.
中文