liveBook · Manning

Task queue

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

A task queue is a data structure that holds submitted tasks awaiting processing in an ordered sequence.

A task queue holds submitted tasks until a worker can process them. In an orchestration system, the manager places new tasks in a pending queue and handles them in first-in, first-out order; workers also contain task queues. section 2.3 section 4.1

The queue connects the main orchestration responsibilities:

  • The manager accepts tasks, stores them as pending, selects suitable workers, and sends work onward. section 2.3
  • The worker uses its queue alongside a runtime and task database to handle assigned work. section 4.1

A pending queue in a manager

A Go Manager skeleton declares Pending as a queue.Queue, alongside task and event maps, worker records, and task-to-worker mappings. Methods such as SelectWorker, UpdateTasks, and SendWork provide the next operations around queued tasks. section 2.3

Listing 2.8 The beginnings of our Manager skeleton
package manager

import(
   "cube/task"
   "fmt"

   "github.com/golang-collections/collections/queue"
   "github.com/google/uuid"
)

type Manager struct {
   Pending       queue.Queue
   TaskDb        map[string][]*task.Task
   EventDb       map[string][]*task.TaskEvent
   Workers       []string
   WorkerTaskMap map[string][]uuid.UUID
   TaskWorkerMap map[uuid.UUID]string
}

Inspect the Manager skeleton to see the queue positioned among task storage, worker tracking, and assignment maps. section 2.3

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

How deep it goes
Defines FIFO ordering and shows the queue in a manager skeleton, but defers detailed queue processing behavior.
Examples
Uses a Go Manager skeleton with Pending, worker mappings, task storage, and placeholder scheduling methods.
What you can do after
Build a basic manager skeleton that stores pending tasks and prepares scheduling operations around workers.
How it connects
Connects task scheduling with workers, runtimes, task databases, task states, and task events.

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.