queue

package
v0.79.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package queue provides a run queue implementation. The queue is a double-ended queue (deque) that allows for efficient adding and removing of elements from both ends. The queue is used to manage the order of Terragrunt runs.

The algorithm for populating the queue is as follows:

  1. Given a list of discovered configurations, start with an empty queue.
  2. Sort configurations alphabetically to ensure deterministic ordering of independent items.
  3. For each discovered configuration: a. If the configuration has no dependencies, append it to the queue. b. Otherwise, find the position after its last dependency. c. Among items that depend on the same dependency, maintain alphabetical order.

The resulting queue will have: - Configurations with no dependencies at the front - Configurations with dependents are ordered after their dependencies - Alphabetical ordering only between items that share the same dependencies

During operations like applies, entries will be dequeued from the front of the queue and run. During operations like destroys, entries will be dequeued from the back of the queue and run. This ensures that dependencies are satisfied in both cases: - For applies: Dependencies (front) are run before their dependents (back) - For destroys: Dependents (back) are run before their dependencies (front)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entries added in v0.77.14

type Entries []*Entry

func (Entries) Entry added in v0.77.14

func (e Entries) Entry(cfg *discovery.DiscoveredConfig) *Entry

Entry returns a given entry from the queue.

type Entry added in v0.77.14

type Entry struct {
	Config *discovery.DiscoveredConfig
	Status Status
}

func (*Entry) IsUp added in v0.77.14

func (e *Entry) IsUp() bool

IsUp returns true if the entry is an "up" command.

func (*Entry) UpdateBlocked added in v0.77.14

func (e *Entry) UpdateBlocked(entries Entries)

UpdateBlocked updates the status of the entry to blocked, if it is blocked. An entry is blocked if:

  1. It is an "up" command (none of destroy, apply -destroy or plan -destroy) and it has dependencies that are not ready.
  2. It is a "down" command (destroy, apply -destroy or plan -destroy) and it has dependents that are not ready.

If the entry isn't blocked, then it is marked as unsorted, and is ready to be sorted.

type Queue

type Queue struct {
	Entries Entries
}

func NewQueue

func NewQueue(discovered discovery.DiscoveredConfigs) (*Queue, error)

NewQueue creates a new queue from a list of discovered configurations. The queue is populated with the correct Terragrunt run order.

Discovered configurations will be sorted based on two criteria:

  1. The discovery context of the configuration: - If the configuration is for an "up" command (none of destroy, apply -destroy or plan -destroy), it will be inserted at the front of the queue, before its dependencies. - Otherwise, it is considered a "down" command, and will be inserted at the back of the queue, after its dependents.

  2. The name of the configuration. Configurations of the same "level" are sorted alphabetically.

Passing configurations that haven't been checked for cycles in their dependency graph is unsafe. If any cycles are present, the queue construction will halt after N iterations, where N is the number of discovered configs, and throw an error.

func (*Queue) Configs added in v0.77.14

func (q *Queue) Configs() discovery.DiscoveredConfigs

Configs returns the queue configs.

type Status added in v0.77.14

type Status byte
const (
	StatusPending Status = iota
	StatusBlocked
	StatusUnsorted
	StatusReady
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL