Skip to content

Commit 63ffcc7

Browse files
refactor: improve docs
1 parent 101df47 commit 63ffcc7

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

coderd/prebuilds/preset_snapshot.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ func (ra *ReconciliationActions) IsNoop() bool {
8787
return ra.Create == 0 && len(ra.DeleteIDs) == 0 && ra.BackoffUntil.IsZero()
8888
}
8989

90-
// MatchesCron checks if the given time matches the cron expression
91-
// Assumes the time is already in the correct timezone
90+
// MatchesCron interprets a cron spec as a continuous time range,
91+
// and returns whether the provided time value falls within that range.
9292
func MatchesCron(cronExpression string, at time.Time) (bool, error) {
9393
sched, err := cron.Weekly(cronExpression)
9494
if err != nil {
@@ -98,14 +98,17 @@ func MatchesCron(cronExpression string, at time.Time) (bool, error) {
9898
return sched.IsWithinRange(at), nil
9999
}
100100

101+
// CalculateDesiredInstances returns the number of desired instances based on the provided time.
102+
// If the time matches any defined autoscaling schedule, the corresponding number of instances is returned.
103+
// Otherwise, it falls back to the default number of instances specified in the prebuild configuration.
101104
func (p PresetSnapshot) CalculateDesiredInstances(at time.Time) (int32, error) {
102105
if !p.Preset.AutoscalingEnabled {
103106
return p.Preset.DesiredInstances.Int32, nil
104107
}
105108

106109
_, err := time.LoadLocation(p.Preset.AutoscalingTimezone)
107110
if err != nil {
108-
return 0, xerrors.Errorf("can't parse location %v: %w", p.Preset.AutoscalingTimezone, err)
111+
return 0, xerrors.Errorf("failed to parse location %v: %w", p.Preset.AutoscalingTimezone, err)
109112
}
110113

111114
// Check each schedule

0 commit comments

Comments
 (0)