liveBook · Manning

Current state

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

The task lifecycle state currently recorded for a task based on the worker's actual condition.

Current state is the task lifecycle state recorded from a worker’s actual condition. A manager treats the worker as authoritative for this state, rather than trusting only its own record of requested work. section 7.3.3 section 7.6

The system keeps two related views: a task event represents desired state, while the worker datastore represents current state. The manager periodically queries each worker and copies back state, start time, finish time, and container ID. section 7.6 section 7.3.3

Treat current state carefully at API and storage boundaries:

  • When a stop request arrives, copy the stored task before changing its state and enqueueing it as desired work. section 5.4
  • Avoid mutating the datastore object directly: datastore values are pointers, so doing so would make current and desired state identical prematurely. section 5.4

Stopping a task

A stop handler finds the task in the worker datastore, copies it, changes the copy to task.Completed, and places the copy on the queue. The stored task continues representing current state until worker processing updates it. section 5.4

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

How deep it goes
Explains state ownership, synchronization fields, pointer aliasing, and copy-before-enqueue behavior, without covering retries.
Examples
Uses task listing, stop requests, copied task values, and manager polling to demonstrate current-state transitions.
What it assumes
Assumes tasks, workers, queues, and manager records; teaches the distinction between requested work and observed execution state.
What you can do after
Operate and synchronize task records by querying workers, identifying stale state, and preserving desired/current-state separation.
How it connects
Connects desired state, task queues, worker APIs, task events, scheduling, and manager synchronization.

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.