MCPcopy Create free account
hub / github.com/coder/coder / NextAllowedAutostart

Function NextAllowedAutostart

coderd/schedule/autostart.go:38–52  ·  view source on GitHub ↗

NextAllowedAutostart returns the next valid autostart time after 'at', based on the workspace's cron schedule and the template's allowed days. It searches up to 7 days ahead to find a match.

(at time.Time, wsSchedule string, templateSchedule TemplateScheduleOptions)

Source from the content-addressed store, hash-verified

36// NextAllowedAutostart returns the next valid autostart time after 'at', based on the workspace's
37// cron schedule and the template's allowed days. It searches up to 7 days ahead to find a match.
38func NextAllowedAutostart(at time.Time, wsSchedule string, templateSchedule TemplateScheduleOptions) (time.Time, error) {
39 next := at
40
41 // Our cron schedules work on a weekly basis, so to ensure we've exhausted all
42 // possible autostart times we need to check up to 7 days worth of autostarts.
43 for next.Sub(at) < 7*24*time.Hour {
44 var valid bool
45 next, valid = NextAutostart(next, wsSchedule, templateSchedule)
46 if valid {
47 return next, nil
48 }
49 }
50
51 return time.Time{}, ErrNoAllowedAutostart
52}

Callers 6

createWorkspaceFunction · 0.92
putWorkspaceAutostartMethod · 0.92
runOnceMethod · 0.92
isEligibleForAutostartFunction · 0.92
TestNextAllowedAutostartFunction · 0.92

Calls 1

NextAutostartFunction · 0.85

Tested by 1

TestNextAllowedAutostartFunction · 0.74