Movatterモバイル変換


[0]ホーム

URL:


unit

package
v2.29.1Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License:AGPL-3.0Imports:8Imported by:0

Details

Repository

github.com/coder/coder

Links

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (ErrUnitIDRequired           =xerrors.New("unit name is required")ErrUnitNotFound             =xerrors.New("unit not found")ErrUnitAlreadyRegistered    =xerrors.New("unit already registered")ErrCannotUpdateOtherUnit    =xerrors.New("cannot update other unit's status")ErrDependenciesNotSatisfied =xerrors.New("unit dependencies not satisfied")ErrSameStatusAlreadySet     =xerrors.New("same status already set")ErrCycleDetected            =xerrors.New("cycle detected")ErrFailedToAddDependency    =xerrors.New("failed to add dependency"))

Functions

This section is empty.

Types

typeDependencyadded inv2.29.0

type Dependency struct {UnitIDDependsOnIDRequiredStatusStatusCurrentStatusStatusIsSatisfiedbool}

Dependency represents a dependency relationship between units.

typeEdge

type Edge[EdgeType, VertexTypecomparable] struct {From VertexTypeTo   VertexTypeEdge EdgeType}

Edge is a convenience type for representing an edge in the graph.It encapsulates the from and to vertices and the edge type itself.

typeGraph

type Graph[EdgeType, VertexTypecomparable] struct {// contains filtered or unexported fields}

Graph provides a bidirectional interface over gonum's directed graph implementation.While the underlying gonum graph is directed, we overlay bidirectional semanticsby distinguishing between forward and reverse edges. Wanting and being wanted byother units are related but different concepts that have different graph traversalimplications when Units update their status.

The graph stores edge types to represent different relationships between units,allowing for domain-specific semantics beyond simple connectivity.

func (*Graph[EdgeType, VertexType])AddEdge

func (g *Graph[EdgeType, VertexType]) AddEdge(from, to VertexType, edge EdgeType)error

AddEdge adds an edge to the graph. It initializes the graph and metadata on first use,checks for cycles, and adds the edge to the gonum graph.

func (*Graph[EdgeType, VertexType])GetForwardAdjacentVertices

func (g *Graph[EdgeType, VertexType]) GetForwardAdjacentVertices(from VertexType) []Edge[EdgeType, VertexType]

GetForwardAdjacentVertices returns all the edges that originate from the given vertex.

func (*Graph[EdgeType, VertexType])GetReverseAdjacentVertices

func (g *Graph[EdgeType, VertexType]) GetReverseAdjacentVertices(to VertexType) []Edge[EdgeType, VertexType]

GetReverseAdjacentVertices returns all the edges that terminate at the given vertex.

func (*Graph[EdgeType, VertexType])ToDOT

func (g *Graph[EdgeType, VertexType]) ToDOT(namestring) (string,error)

ToDOT exports the graph to DOT format for visualization

typeIDadded inv2.29.0

type IDstring

ID provides a type narrowed representation of the unique identifier of a unit.

typeManageradded inv2.29.0

type Manager struct {// contains filtered or unexported fields}

Manager provides reactive dependency tracking over a Graph.It manages Unit registration, dependency relationships, and status updateswith automatic recalculation of readiness when dependencies are satisfied.

funcNewManageradded inv2.29.0

func NewManager() *Manager

NewManager creates a new Manager instance.

func (*Manager)AddDependencyadded inv2.29.0

func (m *Manager) AddDependency(unitID, dependsOnID, requiredStatusStatus)error

AddDependency adds a dependency relationship between units.The unit depends on the dependsOn unit reaching the requiredStatus.

func (*Manager)ExportDOTadded inv2.29.0

func (m *Manager) ExportDOT(namestring) (string,error)

ExportDOT exports the dependency graph to DOT format for visualization.

func (*Manager)GetAllDependenciesadded inv2.29.0

func (m *Manager) GetAllDependencies(unitID) ([]Dependency,error)

GetAllDependencies returns all dependencies for a unit, both satisfied and unsatisfied.

func (*Manager)GetGraphadded inv2.29.0

func (m *Manager) GetGraph() *Graph[Status,ID]

GetGraph returns the underlying graph for visualization and debugging.This should be used carefully as it exposes the internal graph structure.

func (*Manager)GetUnmetDependenciesadded inv2.29.0

func (m *Manager) GetUnmetDependencies(unitID) ([]Dependency,error)

GetUnmetDependencies returns a list of unsatisfied dependencies for a unit.

func (*Manager)IsReadyadded inv2.29.0

func (m *Manager) IsReady(idID) (bool,error)

func (*Manager)Registeradded inv2.29.0

func (m *Manager) Register(idID)error

Register adds a unit to the manager if it is not already registered.If a Unit is already registered (per the ID field), it is not updated.

func (*Manager)Unitadded inv2.29.0

func (m *Manager) Unit(idID) (Unit,error)

Unit fetches a unit from the manager. If the unit does not exist,it returns the Unit zero-value as a placeholder unit, becauseunits may depend on other units that have not yet been created.

func (*Manager)UpdateStatusadded inv2.29.0

func (m *Manager) UpdateStatus(unitID, newStatusStatus)error

UpdateStatus updates a unit's status and recalculates readiness for affected dependents.

typeStatusadded inv2.29.0

type Statusstring

Status represents the status of a unit.

const (StatusNotRegisteredStatus = ""StatusPendingStatus = "pending"StatusStartedStatus = "started"StatusCompleteStatus = "completed")

Status constants for dependency tracking.

func (Status)Stringadded inv2.29.0

func (sStatus) String()string

typeUnitadded inv2.29.0

type Unit struct {// contains filtered or unexported fields}

Unit represents a point-in-time snapshot of a vertex in the dependency graph.Units may depend on other units, or be depended on by other units. The unit structis not aware of updates made to the dependency graph after it is initialized and shouldnot be cached.

func (Unit)IDadded inv2.29.0

func (uUnit) ID()ID

func (Unit)Statusadded inv2.29.0

func (uUnit) Status()Status

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp