8000 feat: implement scheduling mechanism for prebuilds by evgeniy-scherbina · Pull Request #18126 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: implement scheduling mechanism for prebuilds #18126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 46 commits into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
47cb6fc
feat: implement autoscaling mechanism for prebuilds
evgeniy-scherbina May 29, 2025
0f4d521
fix: precision issue with is-within-range function
evgeniy-scherbina Jun 13, 2025
b957eb6
test: fix is-within-range test
evgeniy-scherbina Jun 13, 2025
de920b8
test: minor fixes in is-within-range test
evgeniy-scherbina Jun 13, 2025
5d31b43
test: fix tests failed due to is-within-range function
evgeniy-scherbina Jun 13, 2025
b3130a8
fix: migration numbers
evgeniy-scherbina Jun 13, 2025
0565fb7
feat: define functions for validation of schedules
evgeniy-scherbina Jun 15, 2025
99d76e5
Merge remote-tracking branch 'origin/main' into yevhenii/prebuilds-au…
evgeniy-scherbina Jun 15, 2025
bdfcd9e
regenerate protofiles
evgeniy-scherbina Jun 15, 2025
ea7766f
test: improve test coverage for schedules-overlap function
evgeniy-scherbina Jun 15, 2025
1e78317
test: improve test coverage for validate-schedules function
evgeniy-scherbina Jun 16, 2025
5d99ef1
refactor: add logger to preset-snapshot
evgeniy-scherbina Jun 16, 2025
158b92e
refactor: fallback to default on error in calc-desired-instances
evgeniy-scherbina Jun 16, 2025
396d080
refactor: change signature of calc-desired-instances
evgeniy-scherbina Jun 16, 2025
12dba6c
fix: improve schedule validation
evgeniy-scherbina Jun 16, 2025
3fa98b2
fix: bug related to DOM and DOW interpretation
evgeniy-scherbina Jun 16, 2025
8a063ff
fix: add schedules validation
evgeniy-scherbina Jun 16, 2025
12d3d88
fix: use TimeRange function instead of Weekly
evgeniy-scherbina Jun 16, 2025
3facaf2
fix: linter
evgeniy-scherbina Jun 17, 2025
6ce7ff2
fix: migration numbers
evgeniy-scherbina Jun 17, 2025
178676f
Merge remote-tracking branch 'origin/main' into yevhenii/prebuilds-au…
evgeniy-scherbina Jun 17, 2025
368fb36
deps: update version of tf-provider-coder
evgeniy-scherbina Jun 17, 2025
44b67ae
refactor: use ValidateSchedules from tf-provider-coder
evgeniy-scherbina Jun 17, 2025
df202c2
fix: CR's fixes
evgeniy-scherbina Jun 17, 2025
affee62
Update coderd/database/dbgen/dbgen.go
evgeniy-scherbina Jun 17, 2025
909d950
refactor: rename instances to desired_instances for consistency
evgeniy-scherbina Jun 17, 2025
e08f8d2
fix: make gen
evgeniy-scherbina Jun 17, 2025
4da1e64
fix: migrations test
evgeniy-scherbina Jun 17, 2025
4d2557c
fix: optimize get-preset-prebuild-schedules query
evgeniy-scherbina Jun 17, 2025
faf9ec7
refactor: rename DB method
evgeniy-scherbina Jun 17, 2025
821eda7
refactor: rename autoscaling to scheduling
evgeniy-scherbina Jun 18, 2025
7617042
refactor: rename autoscaling to scheduling (migration files)
evgeniy-scherbina Jun 18, 2025
6c2350f
refactor: minor refactor after renaming
evgeniy-scherbina Jun 18, 2025
cacdb1f
deps: update version of tf-provider-coder
evgeniy-scherbina Jun 18, 2025
8d2c08e
gen: make gen
evgeniy-scherbina Jun 18, 2025
5600054
docs: document api changes in proto/version.go
evgeniy-scherbina Jun 18, 2025
2215a9e
test: extend convert-resources test with prebuilds.scheduling
evgeniy-scherbina Jun 18, 2025
69ab8e1
fix: make gen
evgeniy-scherbina Jun 19, 2025
4a29496
refactor: make fmt
evgeniy-scherbina Jun 19, 2025
8edb051
deps: update version of tf-provider-coder
evgeniy-scherbina Jun 19, 2025
954bf66
Merge remote-tracking branch 'origin/main' into yevhenii/prebuilds-au…
evgeniy-scherbina Jun 19, 2025
2d945cf
fix: migration numbers
evgeniy-scherbina Jun 19, 2025
533a2b5
refactor: fix formatting
evgeniy-scherbina Jun 19, 2025
2b7119a
fix: set scheduling_timezone to empty string by default
evgeniy-scherbina Jun 19, 2025
96caa18
refactor: improve logging
evgeniy-scherbina Jun 19, 2025
83872d6
refactor: improve logging
evgeniy-scherbina Jun 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: use TimeRange function instead of Weekly
  • Loading branch information
evgeniy-scherbina committed Jun 16, 2025
commit 12d3d88e348b1fb18aa0c3d0acd0bff447d044ac
2 changes: 1 addition & 1 deletion coderd/prebuilds/preset_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (ra *ReconciliationActions) IsNoop() bool {
// MatchesCron interprets a cron spec as a continuous time range,
// and returns whether the provided time value falls within that range.
func MatchesCron(cronExpression string, at time.Time) (bool, error) {
sched, err := cron.Weekly(cronExpression)
sched, err := cron.TimeRange(cronExpression)
if err != nil {
return false, xerrors.Errorf("failed to parse cron expression: %w", err)
}
Expand Down
38 changes: 38 additions & 0 deletions coderd/schedule/cron/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,29 @@ func Daily(raw string) (*Schedule, error) {
return parse(raw)
}

// TimeRange parses a Schedule from a cron specification interpreted as a continuous time range.
//
// For example, the expression "* 9-18 * * 1-5" represents a continuous time span
// from 09:00:00 to 18:59:59, Monday through Friday.
//
// The specification consists of space-delimited fields in the following order:
// - (Optional) Timezone, e.g., CRON_TZ=US/Central
// - Minutes: must be "*" to represent the full range within each hour
// - Hour of day: e.g., 9-18 (required)
// - Day of month: e.g., * or 1-15 (required)
// - Month: e.g., * or 1-6 (required)
// - Day of week: e.g., * or 1-5 (required)
//
// Unlike standard cron, this function interprets the input as a continuous active period
// rather than discrete scheduled times.
func TimeRange(raw string) (*Schedule, error) {
if err := validateTimeRangeSpec(raw); err != nil {
return nil, xerrors.Errorf("validate time range schedule: %w", err)
}

return parse(raw)
}

func parse(raw string) (*Schedule, error) {
// If schedule does not specify a timezone, default to UTC. Otherwise,
// the library will default to time.Local which we want to avoid.
Expand Down Expand Up @@ -281,3 +304,18 @@ func validateDailySpec(spec string) error {
}
return nil
}

// validateTimeRangeSpec ensures that the minutes field is set to *
func validateTimeRangeSpec(spec string) error {
parts := strings.Fields(spec)
if len(parts) < 5 {
return xerrors.Errorf("expected schedule to consist of 5 fields with an optional CRON_TZ=<timezone> prefix")
}
if len(parts) == 6 {
parts = parts[1:]
}
if parts[0] != "*" {
return xerrors.Errorf("expected minutes to be *")
}
return nil
}
Loading
0