MCPcopy Create free account
hub / github.com/coder/coder / CalculateActions

Method CalculateActions

coderd/prebuilds/preset_snapshot.go:316–333  ·  view source on GitHub ↗

CalculateActions determines what actions are needed to reconcile the current state with the desired state. The function: 1. First checks if a backoff period is needed (if previous builds failed) 2. If the preset is inactive (template version is not active), it will delete all running prebuilds 3. Fo

(backoffInterval time.Duration)

Source from the content-addressed store, hash-verified

314// - ActionTypeCreate: Only Create is set, indicating how many prebuilds to create
315// - ActionTypeDelete: Only DeleteIDs is set, containing IDs of prebuilds to delete
316func (p PresetSnapshot) CalculateActions(backoffInterval time.Duration) ([]*ReconciliationActions, error) {
317 // TODO: align workspace states with how we represent them on the FE and the CLI
318 // right now there's some slight differences which can lead to additional prebuilds being created
319
320 // TODO: add mechanism to prevent prebuilds being reconciled from being claimable by users; i.e. if a prebuild is
321 // about to be deleted, it should not be deleted if it has been claimed - beware of TOCTOU races!
322
323 actions, needsBackoff := p.needsBackoffPeriod(p.clock, backoffInterval)
324 if needsBackoff {
325 return actions, nil
326 }
327
328 if !p.isActive() {
329 return p.handleInactiveTemplateVersion()
330 }
331
332 return p.handleActiveTemplateVersion()
333}
334
335// isActive returns true if the preset's template version is the active version, and it is neither deleted nor deprecated.
336// This determines whether we should maintain prebuilds for this preset or delete them.

Callers 1

Calls 4

needsBackoffPeriodMethod · 0.95
isActiveMethod · 0.95

Tested by 1