MCPcopy Index your code
hub / github.com/coder/coder / AddDependency

Method AddDependency

agent/unit/manager.go:158–182  ·  view source on GitHub ↗

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

(unit ID, dependsOn ID, requiredStatus Status)

Source from the content-addressed store, hash-verified

156// AddDependency adds a dependency relationship between units.
157// The unit depends on the dependsOn unit reaching the requiredStatus.
158func (m *Manager) AddDependency(unit ID, dependsOn ID, requiredStatus Status) error {
159 m.mu.Lock()
160 defer m.mu.Unlock()
161
162 switch {
163 case unit == "":
164 return xerrors.Errorf("dependent name cannot be empty: %w", ErrUnitIDRequired)
165 case dependsOn == "":
166 return xerrors.Errorf("dependency name cannot be empty: %w", ErrUnitIDRequired)
167 case !m.registered(unit):
168 return xerrors.Errorf("dependent unit %q must be registered first: %w", unit, ErrUnitNotFound)
169 }
170
171 // Add the dependency edge to the graph
172 // The edge goes from unit to dependsOn, representing the dependency
173 err := m.graph.AddEdge(unit, dependsOn, requiredStatus)
174 if err != nil {
175 return xerrors.Errorf("adding edge for unit %q: %w", unit, errors.Join(ErrFailedToAddDependency, err))
176 }
177
178 // Recalculate readiness for the unit since it now has a new dependency
179 m.recalculateReadinessUnsafe(unit)
180
181 return nil
182}
183
184// UpdateStatus updates a unit's status and recalculates readiness for affected dependents.
185func (m *Manager) UpdateStatus(unit ID, newStatus Status) error {

Callers 7

TestManager_UpdateStatusFunction · 0.95
TestManager_ToDOTFunction · 0.95
SyncWantMethod · 0.80

Calls 6

registeredMethod · 0.95
AddEdgeMethod · 0.80
LockMethod · 0.45
UnlockMethod · 0.45
ErrorfMethod · 0.45

Tested by 6

TestManager_UpdateStatusFunction · 0.76
TestManager_ToDOTFunction · 0.76