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

Method CalculateState

coderd/prebuilds/preset_snapshot.go:265–299  ·  view source on GitHub ↗

CalculateState computes the current state of prebuilds for a preset, including: - Actual: Number of currently running prebuilds, i.e., non-expired and expired prebuilds - Expired: Number of currently running expired prebuilds - Desired: Number of prebuilds desired as defined in the preset - Eligible

()

Source from the content-addressed store, hash-verified

263// in-progress transitions. This state information is used to determine what reconciliation
264// actions are needed to reach the desired state.
265func (p PresetSnapshot) CalculateState() *ReconciliationState {
266 var (
267 actual int32
268 desired int32
269 expired int32
270 eligible int32
271 extraneous int32
272 )
273
274 // #nosec G115 - Safe conversion as p.Running and p.Expired slice length is expected to be within int32 range
275 actual = int32(len(p.Running) + len(p.Expired))
276
277 // #nosec G115 - Safe conversion as p.Expired slice length is expected to be within int32 range
278 expired = int32(len(p.Expired))
279
280 if p.isActive() {
281 desired = p.CalculateDesiredInstances(p.clock.Now())
282 eligible = p.countEligible()
283 extraneous = max(actual-expired-desired, 0)
284 }
285
286 starting, stopping, deleting := p.countInProgress()
287
288 return &ReconciliationState{
289 Actual: actual,
290 Expired: expired,
291 Desired: desired,
292 Eligible: eligible,
293 Extraneous: extraneous,
294
295 Starting: starting,
296 Stopping: stopping,
297 Deleting: deleting,
298 }
299}
300
301// CalculateActions determines what actions are needed to reconcile the current state with the desired state.
302// The function:

Callers 15

TestNoPrebuildsFunction · 0.80
TestNetNewFunction · 0.80
TestOutdatedPrebuildsFunction · 0.80
TestInProgressActionsFunction · 0.80
TestExtraneousFunction · 0.80
TestExpiredPrebuildsFunction · 0.80
TestDeprecatedFunction · 0.80
TestLatestBuildFailedFunction · 0.80
TestPrebuildSchedulingFunction · 0.80

Calls 4

isActiveMethod · 0.95
countEligibleMethod · 0.95
countInProgressMethod · 0.95

Tested by 12

TestNoPrebuildsFunction · 0.64
TestNetNewFunction · 0.64
TestOutdatedPrebuildsFunction · 0.64
TestInProgressActionsFunction · 0.64
TestExtraneousFunction · 0.64
TestExpiredPrebuildsFunction · 0.64
TestDeprecatedFunction · 0.64
TestLatestBuildFailedFunction · 0.64
TestPrebuildSchedulingFunction · 0.64
TestFailedBuildBackoffFunction · 0.64