Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitff41e18

Browse files
minor fixes
1 parent6cae709 commitff41e18

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

‎coderd/prebuilds/preset_snapshot.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ import (
55
"slices"
66
"time"
77

8-
"golang.org/x/xerrors"
9-
10-
"github.com/coder/coder/v2/coderd/schedule/cron"
11-
12-
"github.com/google/uuid"
13-
148
"github.com/coder/quartz"
9+
"github.com/google/uuid"
10+
"golang.org/x/xerrors"
1511

1612
"github.com/coder/coder/v2/coderd/database"
13+
"github.com/coder/coder/v2/coderd/schedule/cron"
1714
)
1815

1916
// ActionType represents the type of action needed to reconcile prebuilds.
@@ -106,16 +103,19 @@ func MatchesCron(cronExpression string, at time.Time) (bool, error) {
106103
// Otherwise, it falls back to the default number of instances specified in the prebuild configuration.
107104
func (pPresetSnapshot)CalculateDesiredInstances(at time.Time) (int32,error) {
108105
iflen(p.PrebuildSchedules)==0 {
106+
// If no schedules are defined, fall back to the default desired instance count
109107
returnp.Preset.DesiredInstances.Int32,nil
110108
}
111109

110+
// Validate that the provided timezone is valid
112111
_,err:=time.LoadLocation(p.Preset.AutoscalingTimezone)
113112
iferr!=nil {
114113
return0,xerrors.Errorf("failed to parse location %v: %w",p.Preset.AutoscalingTimezone,err)
115114
}
116115

117-
//Check eachschedule
116+
//Look for aschedule whose cron expression matches the provided time
118117
for_,schedule:=rangep.PrebuildSchedules {
118+
// Prefix the cron expression with timezone information
119119
cronExprWithTimezone:=fmt.Sprintf("CRON_TZ=%s %s",p.Preset.AutoscalingTimezone,schedule.CronExpression)
120120
matches,err:=MatchesCron(cronExprWithTimezone,at)
121121
iferr!=nil {
@@ -126,6 +126,7 @@ func (p PresetSnapshot) CalculateDesiredInstances(at time.Time) (int32, error) {
126126
}
127127
}
128128

129+
// If no schedule matches, fall back to the default desired instance count
129130
returnp.Preset.DesiredInstances.Int32,nil
130131
}
131132

@@ -160,8 +161,9 @@ func (p PresetSnapshot) CalculateState() *ReconciliationState {
160161
varerrerror
161162
desired,err=p.CalculateDesiredInstances(p.clock.Now())
162163
iferr!=nil {
163-
// TODO: handle error
164-
panic(err)
164+
// In case of an error, fall back to the default desired instance count
165+
desired=p.Preset.DesiredInstances.Int32
166+
// TODO: log error
165167
}
166168
eligible=p.countEligible()
167169
extraneous=max(actual-expired-desired,0)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp