MCPcopy Index your code
hub / github.com/coder/coder / NextAutostart

Function NextAutostart

coderd/schedule/autostart.go:16–34  ·  view source on GitHub ↗

NextAutostart takes the workspace and template schedule and returns the next autostart schedule after "at". The boolean returned is if the autostart should be allowed to start based on the template schedule.

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

Source from the content-addressed store, hash-verified

14// after "at". The boolean returned is if the autostart should be allowed to start based on the template
15// schedule.
16func NextAutostart(at time.Time, wsSchedule string, templateSchedule TemplateScheduleOptions) (time.Time, bool) {
17 sched, err := cron.Weekly(wsSchedule)
18 if err != nil {
19 return time.Time{}, false
20 }
21
22 // Round down to the nearest minute, as this is the finest granularity cron supports.
23 // Truncate is probably not necessary here, but doing it anyway to be sure.
24 nextTransition := sched.Next(at).Truncate(time.Minute)
25
26 // The nextTransition is when the auto start should kick off. If it lands on a
27 // forbidden day, do not allow the auto start. We use the time location of the
28 // schedule to determine the weekday. So if "Saturday" is disallowed, the
29 // definition of "Saturday" depends on the location of the schedule.
30 zonedTransition := nextTransition.In(sched.Location())
31 allowed := templateSchedule.AutostartRequirement.DaysMap()[zonedTransition.Weekday()]
32
33 return zonedTransition, allowed
34}
35
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.

Callers 4

ReportAgentStatsMethod · 0.92
TestNextAllowedAutostartFunction · 0.92
NextAllowedAutostartFunction · 0.85
CalculateAutostopFunction · 0.85

Calls 4

WeeklyFunction · 0.92
LocationMethod · 0.80
NextMethod · 0.65
DaysMapMethod · 0.45

Tested by 1

TestNextAllowedAutostartFunction · 0.74