liveBook · Manning

Failed state

As explained in Build and Orchestrator in Go (From Scratch)

The failed state is the lifecycle state of a task that has crashed or stopped working as expected.

The failed state marks a task that has crashed or stopped working as expected. It is one of five task lifecycle states—Pending, Scheduled, Running, Completed, and Failed—and represents unsuccessful execution rather than normal completion or user-initiated stopping. section 2.1 section 4.6.3

A worker and manager use the state to decide what actions are valid. Scheduling or starting a task can produce Failed when the operation does not succeed: Pending can become Failed during scheduling, while Scheduled or Running can become Failed during startup or execution. Failed has no outgoing transitions in the defined transition map, so it is terminal. section 2.7 section 4.6.3

The minimal implementation models failure explicitly:

  • Represent Failed as a value in the Go State type alongside Pending, Scheduled, Running, and Completed. section 2.1
  • Permit transitions from Pending, Scheduled, or Running to Failed when the corresponding scheduling, startup, or execution event fails. section 4.6.3 section 4.6.3
  • Reject transitions out of Failed by assigning it an empty destination list. section 4.6.3
Table 4.1 State transition table showing the valid transitions from one state to another (view table figure)

CurrentState

Event

NextState

Pending

ScheduleEvent

Scheduled

Pending

ScheduleEvent

Failed

Scheduled

StartTask

Running

Scheduled

StartTask

Failed

Running

StopTask

Completed

Use the transition table to inspect which events can move a task into Failed and which lifecycle states have no recovery path. section 4.6.3

How Build and Orchestrator in Go (From Scratch) covers it

How deep it goes
Defines failure semantically and implements valid transitions, stopping short of recovery behavior after failure.
Examples
Uses scheduling failure, container startup failure, and task crashes to illustrate transitions into Failed.
What it assumes
Assumes basic task orchestration concepts while defining the lifecycle states and transition rules explicitly.
What you can do after
Implement it via a Go state-transition map and validate whether requested task transitions are allowed.
How it connects
Connects task lifecycle states with workers, managers, schedulers, state transitions, and Docker containers.

This explainer was generated by Manning's knowledge graph from the text of Build and Orchestrator in Go (From Scratch). The section links point to the parts of the book it draws on.