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

Method UpdateStatus

agent/unit/manager.go:185–213  ·  view source on GitHub ↗

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

(unit ID, newStatus Status)

Source from the content-addressed store, hash-verified

183
184// UpdateStatus updates a unit's status and recalculates readiness for affected dependents.
185func (m *Manager) UpdateStatus(unit ID, newStatus Status) error {
186 m.mu.Lock()
187 defer m.mu.Unlock()
188
189 switch {
190 case unit == "":
191 return xerrors.Errorf("updating status for unit %q: %w", unit, ErrUnitIDRequired)
192 case !m.registered(unit):
193 return xerrors.Errorf("unit %q must be registered first: %w", unit, ErrUnitNotFound)
194 }
195
196 u := m.units[unit]
197 if u.status == newStatus {
198 return xerrors.Errorf("checking status for unit %q: %w", unit, ErrSameStatusAlreadySet)
199 }
200
201 u.status = newStatus
202 m.units[unit] = u
203
204 // Get all units that depend on this one (reverse adjacent vertices)
205 dependents := m.graph.GetReverseAdjacentVertices(unit)
206
207 // Recalculate readiness for all dependents
208 for _, dependent := range dependents {
209 m.recalculateReadinessUnsafe(dependent.From)
210 }
211
212 return nil
213}
214
215// recalculateReadinessUnsafe recalculates the readiness state for a unit.
216// This method assumes the caller holds the write lock.

Calls 6

registeredMethod · 0.95
LockMethod · 0.45
UnlockMethod · 0.45
ErrorfMethod · 0.45

Tested by 6

TestManager_RegisterFunction · 0.76
TestManager_UpdateStatusFunction · 0.76