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
type Config struct {
Location *time.Location
}
| Field | Default | Effect |
|---|---|---|
Location |
time.Local |
Timezone used to compute the next fire time of cron expressions and descriptors |
loc, err := time.LoadLocation("Asia/Taipei")
if err != nil {
log.Fatal(err)
}
c, err := core.New(core.Config{Location: loc})
if err != nil {
log.Fatal(err)
}
if _, err := c.Add("30 9 * * 1-5", func() error {
return sendReport()
}, "weekday report"); err != nil {
log.Fatal(err)
}
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:
func (c *cron) Add(spec string, action interface{}, arg ...interface{}) (int64, error)
| Type | Sets | Notes |
|---|---|---|
string |
Task description | Logged by the dependency worker |
time.Duration |
Execution limit | Not a start delay; 0 means no limit |
func() |
Timeout callback | Called only when the execution limit is exceeded |
[]core.Wait |
Prerequisites | Action must be func() error |
[]int64 |
Prerequisites (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.
_, err := c.Add("*/10 * * * *", func() error {
return syncInventory()
}, "inventory sync", 2*time.Minute, func() {
log.Println("inventory sync exceeded 2m")
}, []core.Wait{
{ID: authID, State: core.Stop},
{ID: cacheID, State: core.Skip},
})
if err != nil {
log.Fatal(err)
}
Dependency Settings
| Field | Value | Effect |
|---|---|---|
ID |
Prerequisite task ID | Dependent task fails when the ID does not exist |
State |
core.Stop (default) |
Dependent task fails when the prerequisite fails |
State |
core.Skip |
Failed prerequisite is ignored |
Delay |
Any | Currently not applied; the wait limit is fixed at 1 minute |
Runtime Defaults
| Item | Value | Source |
|---|---|---|
| Logger | syslog (LOG_INFO|LOG_LOCAL0, tag goCron) in JSON |
core/instance.go |
| Logger fallback | stderr text, Info level | When syslog cannot be opened |
| Dependency workers | runtime.NumCPU(), or 2 when CPUs ≤ 2 |
core/depend.go |
| Wait queue capacity | 1024 | core/depend.go |
| Dependency poll interval | 1ms | core/dependManager.go |
@every minimum interval |
30 seconds | core/schedule.go |
None of these values can be changed by callers.
See Task Dependencies and Timeouts for runtime behavior.