go.temporal.io/server/common/backoff/cron.go
73 LOC · 42 covered · 31 uncovered · 18 ranges · 161 concepts · 13 introducers · 91 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
package backoff
import (
"time"
"github.com/robfig/cron/v3"
"go.temporal.io/api/serviceerror"
"go.temporal.io/server/common/convert"
)
// NoBackoff is used to represent backoff when no cron backoff is needed
const NoBackoff = time.Duration(-1)
// ValidateSchedule validates a cron schedule spec
if cronSchedule == "" {
}
if err != nil {
}
if nextTime.IsZero() {
return serviceerror.NewInvalidArgument("invalid CronSchedule, no time can be found to satisfy the schedule")
}
}
// GetBackoffForNextSchedule calculates the backoff time for the next run given
// a cronSchedule, current scheduled time, and now.
func GetBackoffForNextSchedule(cronSchedule string, scheduledTime time.Time, now time.Time) time.Duration {
cron.go ×1
if len(cronSchedule) == 0 {
}
if err != nil {
return NoBackoff
}
nowUTC := now.UTC()
var nextScheduleTime time.Time
if nowUTC.Before(scheduledUTCTime) {
// Calculate the next schedule start time which is nearest to now (right after now).
for !nextScheduleTime.IsZero() && nextScheduleTime.Before(nowUTC) {
}
}
// no time can be found to satisfy the schedule
return NoBackoff
}
roundedInterval := time.Second * time.Duration(convert.Int64Ceil(backoffInterval.Seconds()))
return roundedInterval
}
// GetBackoffForNextScheduleNonNegative calculates the backoff time and ensures a non-negative duration.
func GetBackoffForNextScheduleNonNegative(cronSchedule string, scheduledTime time.Time, now time.Time) time.Duration {
util.go ×5
backoffDuration := GetBackoffForNextSchedule(cronSchedule, scheduledTime, now)
if backoffDuration == NoBackoff || backoffDuration < 0 {
backoffDuration = 0
}
return backoffDuration
}