liveBook · Manning

Completed state

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

The completed state is the lifecycle state of a task that has finished successfully or has been stopped by a user.

The completed state marks a task that has finished normally or has been stopped by a user. It is the final lifecycle state after Running, separating successful termination from failure. section 2.1 section 4.6.3

Treat Completed as a state with explicit transition rules:

  • A running task reaches Completed when a StopTask event stops it. section 4.6.3
  • A task that completes its work normally reaches Completed rather than Failed. section 2.1 section 4.6.3
  • The transition map gives Completed no valid next states, making it terminal. section 4.6.3

Representing completion in Go

A Go state enum includes Completed between Running and Failed. A Task can record StartTime and FinishTime, while TaskEvent captures the resulting state and timestamp for observers. section 2.1

Listing 4.10 The stateTransitionMap map
var stateTransitionMap = map[State][]State{
   Pending:   []State{Scheduled},
   Scheduled: []State{Scheduled, Running, Failed},
   Running:   []State{Running, Completed, Failed},
   Completed: []State{},
   Failed:    []State{},
}

Inspect the transition map to see that Running may move to Completed, while Completed cannot move onward. section 4.6.3

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

How deep it goes
Defines normal completion and user stopping, then encodes Completed as a terminal state with no outgoing transitions.
Examples
Uses Go state constants, a transition map, StopTask, task timestamps, and timestamped TaskEvent records.
What you can do after
Evaluate/understand task termination and verify whether transitions into or out of Completed are valid.
How it connects
Connects task lifecycle, Running, Failed, StopTask, workers, managers, and state transition validation.

Related concepts

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.