v1.2.1

Task Model

Last updated


This page explains what a go-scheduler task holds and which states it moves through.

Task Fields


A task registered with Add holds a schedule, an action, a description, an execution limit, a timeout callback, and a prerequisite list, and receives an increasing int64 ID from atomic.AddInt64.
Action typeInitial stateDependencies allowedFailure sources
func()TaskCompletedNo, Add returns an errorpanic (when no execution limit is set), timeout
func() errorTaskPendingYesreturned error, panic (when no execution limit is set), timeout

A panic is recovered and recorded as TaskFailed only when the task has no execution limit. With a time.Duration limit the action runs in its own goroutine without recover, so a panic terminates the process; see Timeouts.

Task States


  1. const (
  2. TaskPending int = iota
  3. TaskRunning
  4. TaskCompleted
  5. TaskFailed
  6. )

TransitionTrigger
TaskPending → TaskRunningFire time reached and dependencies (if any) satisfied
TaskRunning → TaskCompletedAction returns normally
TaskRunning → TaskFailedReturned error, recovered panic, or execution limit exceeded
TaskPending → TaskFailedPrerequisite failed (Stop), prerequisite missing, or wait timeout
TaskCompleted / TaskFailed → TaskRunningNext trigger of a task without dependencies

States never return to TaskPending. A task with dependencies skips later triggers while its state is TaskRunning or TaskCompleted; because the state stays TaskCompleted after a successful run, such a task completes at most once, while a TaskFailed dependent task is evaluated again on its next trigger.

中文