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)
| 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. |
| 38 | func 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 | } |