liveBook · Manning

Task event

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

A task event is an internal object that records a requested task state transition and the time it was requested, while carrying the associated task.

A task event is an internal record of a requested task state transition. It gives the request its own UUID, records the target state and request time, and carries the associated task. Users act on tasks rather than directly manipulating events. section 2.1

This separates desired state from observed state. The requested transition is retained as a task event in the manager’s EventDB, while TaskDB records the worker-reported state of the task. section 7.6

A minimal Go representation contains:

  • ID: a UUID identifying the event. section 2.1
  • State: the state the task should move toward, such as Running or Completed. section 2.1
  • Timestamp: when the transition was requested. section 2.1
  • Task: the task whose state is being requested. section 2.1

From request to worker

A start request can be decoded from JSON into a TaskEvent. The handler then takes the event’s Task and adds that task to the worker, returning the task in the response. A small test program also constructs an event with a new UUID, Pending state, time.Now(), and a task value before printing it. section 5.4 section 2.6

Figure 2.2 The states a task will go through during its life cycle
02-02

Use the lifecycle diagram to place an event’s requested state among Pending, Scheduled, Running, Completed, and Failed. section 2.1

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

How deep it goes
Defines four fields and demonstrates construction, JSON decoding, and use in a minimal running program.
Examples
Constructs a Pending event with time.Now() and decodes a start-request JSON body into a TaskEvent.
What you can do after
Build it from scratch as a four-field Go struct and pass its carried task through request handling.
How it connects
Connects Task, State, Manager, Worker, EventDB, TaskDB, JSON, and HTTP request handling.

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.