queue

package
v0.99.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: MIT Imports: 6 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 component.Component) *Entry

Entry returns a given entry from the queue.

type Entry added in v0.77.14

type Entry struct {
	// Component is the Terragrunt configuration associated with this entry. It contains all metadata about the unit/stack,
	// including its path, dependencies, and discovery context (such as the command being run).
	Component component.Component

	// Status represents the current lifecycle state of this entry in the queue. It tracks whether the entry is pending,
	// blocked, ready, running, succeeded, or failed. Status is updated as dependencies are resolved and as execution progresses.
	Status Status
}

Entry represents a node in the execution queue/DAG. Each Entry corresponds to a single Terragrunt configuration and tracks its execution status and relationships to other entries in the queue.

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 is a list of entries in the queue.
	Entries Entries

	// FailFast, if set to true, causes the queue to fail fast if any entry fails.
	FailFast bool
	// IgnoreDependencyOrder, if set to true, causes the queue to ignore dependencies when fetching ready entries.
	// When enabled, GetReadyWithDependencies will return all entries with StatusReady, regardless of dependency status.
	IgnoreDependencyOrder bool
	// IgnoreDependencyErrors, if set to true, allows scheduling and running entries even if their
	// dependencies failed. Additionally, failures will not propagate EarlyExit to dependents/dependencies.
	IgnoreDependencyErrors bool
	// contains filtered or unexported fields
}

func NewQueue

func NewQueue(discovered component.Components) (*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) Components added in v0.91.3

func (q *Queue) Components() component.Components

Components returns the queue components.

func (*Queue) EntryByPath added in v0.83.0

func (q *Queue) EntryByPath(path string) *Entry

EntryByPath returns the entry with the given config path, or nil if not found.

func (*Queue) FailEntry added in v0.83.0

func (q *Queue) FailEntry(e *Entry)

FailEntry marks the entry as failed and updates related entries if needed. For up commands, this marks entries that come after this one as early exit. For destroy/down commands, this marks entries that come before this one as early exit. Use only for failure transitions. For other status changes, set Status directly.

func (*Queue) Finished added in v0.83.0

func (q *Queue) Finished() bool

Finished checks if all entries in the queue are in a terminal state (i.e., not pending, blocked, ready, or running).

func (*Queue) GetReadyWithDependencies added in v0.83.0

func (q *Queue) GetReadyWithDependencies(l log.Logger) []*Entry

GetReadyWithDependencies returns all entries that are ready to run and have all dependencies completed (or no dependencies).

func (*Queue) RemainingDeps added in v0.83.0

func (q *Queue) RemainingDeps(e *Entry) int

RemainingDeps Helper to calculate remaining dependencies for an entry.

func (*Queue) SetEntryStatus added in v0.87.6

func (q *Queue) SetEntryStatus(e *Entry, status Status)

SetEntryStatus safely sets the status of an entry with proper synchronization.

If the entry is already in a terminal state (StatusSucceeded, StatusFailed, or StatusEarlyExit), this operation is a no-op. This prevents race conditions where a concurrent success could overwrite an early-exit status set by fail-fast mode.

func (*Queue) SetUnitsMap added in v0.95.0

func (q *Queue) SetUnitsMap(unitsMap map[string]*component.Unit)

SetUnitsMap sets the units map for the queue. This map is used to check if dependencies not in the queue are assumed already applied or have existing state.

type Status added in v0.77.14

type Status byte

Status represents the lifecycle state of a task in the queue.

const (
	StatusPending Status = iota
	StatusBlocked
	StatusUnsorted
	StatusReady
	StatusRunning
	StatusSucceeded
	StatusFailed
	StatusEarlyExit // Terminal status set on Entries in case of fail fast mode
)

Jump to

Keyboard shortcuts

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