Skip to content

Commit 0fdd096

Browse files
refactor: CR's fixes
1 parent 701e2a8 commit 0fdd096

File tree

3 files changed

+29
-33
lines changed

3 files changed

+29
-33
lines changed

coderd/prebuilds/global_snapshot.go

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import (
1010

1111
// GlobalSnapshot represents a full point-in-time snapshot of state relating to prebuilds across all templates.
1212
type GlobalSnapshot struct {
13-
Presets []database.GetTemplatePresetsWithPrebuildsRow
14-
RunningPrebuilds []database.GetRunningPrebuiltWorkspacesRow
15-
PrebuildsInProgress []database.CountInProgressPrebuildsRow
16-
Backoffs []database.GetPresetsBackoffRow
17-
HardLimitedPresetMap map[uuid.UUID]database.GetPresetsAtFailureLimitRow
13+
Presets []database.GetTemplatePresetsWithPrebuildsRow
14+
RunningPrebuilds []database.GetRunningPrebuiltWorkspacesRow
15+
PrebuildsInProgress []database.CountInProgressPrebuildsRow
16+
Backoffs []database.GetPresetsBackoffRow
17+
HardLimitedPresets []database.GetPresetsAtFailureLimitRow
1818
}
1919

2020
func NewGlobalSnapshot(
@@ -24,17 +24,12 @@ func NewGlobalSnapshot(
2424
backoffs []database.GetPresetsBackoffRow,
2525
hardLimitedPresets []database.GetPresetsAtFailureLimitRow,
2626
) GlobalSnapshot {
27-
hardLimitedPresetMap := make(map[uuid.UUID]database.GetPresetsAtFailureLimitRow, len(hardLimitedPresets))
28-
for _, preset := range hardLimitedPresets {
29-
hardLimitedPresetMap[preset.PresetID] = preset
30-
}
31-
3227
return GlobalSnapshot{
33-
Presets: presets,
34-
RunningPrebuilds: runningPrebuilds,
35-
PrebuildsInProgress: prebuildsInProgress,
36-
Backoffs: backoffs,
37-
HardLimitedPresetMap: hardLimitedPresetMap,
28+
Presets: presets,
29+
RunningPrebuilds: runningPrebuilds,
30+
PrebuildsInProgress: prebuildsInProgress,
31+
Backoffs: backoffs,
32+
HardLimitedPresets: hardLimitedPresets,
3833
}
3934
}
4035

@@ -65,15 +60,15 @@ func (s GlobalSnapshot) FilterByPreset(presetID uuid.UUID) (*PresetSnapshot, err
6560
backoffPtr = &backoff
6661
}
6762

63+
_, isHardLimited := slice.Find(s.HardLimitedPresets, func(row database.GetPresetsAtFailureLimitRow) bool {
64+
return row.PresetID == preset.ID
65+
})
66+
6867
return &PresetSnapshot{
69-
Preset: preset,
70-
Running: running,
71-
InProgress: inProgress,
72-
Backoff: backoffPtr,
68+
Preset: preset,
69+
Running: running,
70+
InProgress: inProgress,
71+
Backoff: backoffPtr,
72+
IsHardLimited: isHardLimited,
7373
}, nil
7474
}
75-
76-
func (s GlobalSnapshot) IsHardLimited(presetID uuid.UUID) bool {
77-
_, ok := s.HardLimitedPresetMap[presetID]
78-
return ok
79-
}

coderd/prebuilds/preset_snapshot.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ const (
3232
// It contains the raw data needed to calculate the current state of a preset's prebuilds,
3333
// including running prebuilds, in-progress builds, and backoff information.
3434
type PresetSnapshot struct {
35-
Preset database.GetTemplatePresetsWithPrebuildsRow
36-
Running []database.GetRunningPrebuiltWorkspacesRow
37-
InProgress []database.CountInProgressPrebuildsRow
38-
Backoff *database.GetPresetsBackoffRow
35+
Preset database.GetTemplatePresetsWithPrebuildsRow
36+
Running []database.GetRunningPrebuiltWorkspacesRow
37+
InProgress []database.CountInProgressPrebuildsRow
38+
Backoff *database.GetPresetsBackoffRow
39+
IsHardLimited bool
3940
}
4041

4142
// ReconciliationState represents the processed state of a preset's prebuilds,

enterprise/coderd/prebuilds/reconcile.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,6 @@ func (c *StoreReconciler) ReconcileAll(ctx context.Context) error {
243243
var eg errgroup.Group
244244
// Reconcile presets in parallel. Each preset in its own goroutine.
245245
for _, preset := range snapshot.Presets {
246-
if snapshot.IsHardLimited(preset.ID) {
247-
logger.Debug(ctx, "skipping hard limited preset", slog.F("preset_id", preset.ID), slog.F("name", preset.Name))
248-
continue
249-
}
250-
251246
ps, err := snapshot.FilterByPreset(preset.ID)
252247
if err != nil {
253248
logger.Warn(ctx, "failed to find preset snapshot", slog.Error(err), slog.F("preset_id", preset.ID.String()))
@@ -345,6 +340,11 @@ func (c *StoreReconciler) ReconcilePreset(ctx context.Context, ps prebuilds.Pres
345340
slog.F("preset_name", ps.Preset.Name),
346341
)
347342

343+
if ps.IsHardLimited {
344+
logger.Debug(ctx, "skipping hard limited preset", slog.F("preset_id", ps.Preset.ID), slog.F("name", ps.Preset.Name))
345+
return nil
346+
}
347+
348348
state := ps.CalculateState()
349349
actions, err := c.CalculateActions(ctx, ps)
350350
if err != nil {

0 commit comments

Comments
 (0)