Skip to content

Commit 158b92e

Browse files
refactor: fallback to default on error in calc-desired-instances
1 parent 5d99ef1 commit 158b92e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

coderd/prebuilds/preset_snapshot.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package prebuilds
22

33
import (
4+
"context"
45
"fmt"
56
"slices"
67
"time"
@@ -137,7 +138,13 @@ func (p PresetSnapshot) CalculateDesiredInstances(at time.Time) (int32, error) {
137138
// Validate that the provided timezone is valid
138139
_, err := time.LoadLocation(p.Preset.AutoscalingTimezone)
139140
if err != nil {
140-
return 0, xerrors.Errorf("failed to parse location %v: %w", p.Preset.AutoscalingTimezone, err)
141+
p.logger.Error(context.Background(), "invalid timezone in prebuild autoscaling configuration",
142+
slog.F("preset_id", p.Preset.ID),
143+
slog.F("timezone", p.Preset.AutoscalingTimezone),
144+
slog.Error(err))
145+
146+
// If timezone is invalid, fall back to the default desired instance count
147+
return p.Preset.DesiredInstances.Int32, nil
141148
}
142149

143150
// Look for a schedule whose cron expression matches the provided time
@@ -146,7 +153,11 @@ func (p PresetSnapshot) CalculateDesiredInstances(at time.Time) (int32, error) {
146153
cronExprWithTimezone := fmt.Sprintf("CRON_TZ=%s %s", p.Preset.AutoscalingTimezone, schedule.CronExpression)
147154
matches, err := MatchesCron(cronExprWithTimezone, at)
148155
if err != nil {
149-
return 0, xerrors.Errorf("failed to match cron expression: %w", err)
156+
p.logger.Error(context.Background(), "cron expression is invalid",
157+
slog.F("preset_id", p.Preset.ID),
158+
slog.F("cron_expression", cronExprWithTimezone),
159+
slog.Error(err))
160+
continue
150161
}
151162
if matches {
152163
return schedule.Instances, nil

0 commit comments

Comments
 (0)