liveBook · Manning

Task store

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

A task store is a component that stores and retrieves task records through a defined store interface.

A task store saves and retrieves task records through a Store interface. Wrapping the underlying map keeps the manager independent from map mechanics while allowing both manager and worker to persist tasks. section 11.3

Saving a started task

When the manager receives POST /tasks, it calls Put to save the task locally, then sends the task to the worker, which calls Put in its own store.

Listing 11.3 The InMemoryTaskStore struct
type InMemoryTaskStore struct {
   Db map[string]*task.Task
}

func NewInMemoryTaskStore() *InMemoryTaskStore {
   return &InMemoryTaskStore{
       Db: make(map[string]*task.Task),
   }
}

Inspect the minimal in-memory store structure and constructor. section 11.3

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

How deep it goes
Defines a map-backed implementation and its Put, Get, List, and Count operations, without covering a general store or production persistence.
Examples
Uses InMemoryTaskStore code, Put and Get operations, task listing and counting, and a manager-worker save sequence.
What it assumes
Assumes Go maps, structs, pointers, interfaces, and methods while keeping the storage abstraction explicit.
What you can do after
Build it from scratch as a map-backed task store implementing storage, retrieval, listing, counting, and type validation.
How it connects
Connects the Store interface, Go maps, tasks, the manager, the worker, and the task events store.

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.