13
14
// ValidateSchedule validates a cron schedule spec
16
>
if cronSchedule == "" {
17
return nil
18
}
20
>
if err != nil {
21
return serviceerror.NewInvalidArgument("invalid CronSchedule.")
22
}
24
>
if nextTime.IsZero() {
25
// no time can be found to satisfy the schedule
26
return serviceerror.NewInvalidArgument("invalid CronSchedule, no time can be found to satisfy the schedule")
27
}
29
}
30
31
// GetBackoffForNextSchedule calculates the backoff time for the next run given
32
// a cronSchedule, current scheduled time, and now.
33
>
func GetBackoffForNextSchedule(cronSchedule string, scheduledTime time.Time, now time.Time) time.Duration {
cron.go
34
>
if len(cronSchedule) == 0 {
35
return NoBackoff
36
}
37
39
>
if err != nil {
40
return NoBackoff
41
}
42
44
>
nowUTC := now.UTC()
45
>
46
>
var nextScheduleTime time.Time
47
>
if nowUTC.Before(scheduledUTCTime) {
50
nextScheduleTime = schedule.Next(scheduledUTCTime)
51
// Calculate the next schedule start time which is nearest to now (right after now).