@@ -87,8 +87,8 @@ func (ra *ReconciliationActions) IsNoop() bool {
87
87
return ra .Create == 0 && len (ra .DeleteIDs ) == 0 && ra .BackoffUntil .IsZero ()
88
88
}
89
89
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.
92
92
func MatchesCron (cronExpression string , at time.Time ) (bool , error ) {
93
93
sched , err := cron .Weekly (cronExpression )
94
94
if err != nil {
@@ -98,14 +98,17 @@ func MatchesCron(cronExpression string, at time.Time) (bool, error) {
98
98
return sched .IsWithinRange (at ), nil
99
99
}
100
100
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.
101
104
func (p PresetSnapshot ) CalculateDesiredInstances (at time.Time ) (int32 , error ) {
102
105
if ! p .Preset .AutoscalingEnabled {
103
106
return p .Preset .DesiredInstances .Int32 , nil
104
107
}
105
108
106
109
_ , err := time .LoadLocation (p .Preset .AutoscalingTimezone )
107
110
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 )
109
112
}
110
113
111
114
// Check each schedule
0 commit comments