MCPcopy Create free account
hub / github.com/DoNewsCode/core / TimeoutIfOverlap

Function TimeoutIfOverlap

cron/options.go:129–141  ·  view source on GitHub ↗

TimeoutIfOverlap returns a new JobDescriptor that will cancel the job's context if the next schedule is due.

()

Source from the content-addressed store, hash-verified

127
128// TimeoutIfOverlap returns a new JobDescriptor that will cancel the job's context if the next schedule is due.
129func TimeoutIfOverlap() JobOption {
130 return func(descriptor *JobDescriptor) {
131 innerRun := descriptor.Run
132 descriptor.Run = func(ctx context.Context) error {
133 if !GetNextSchedule(ctx).IsZero() {
134 ctx, cancel := context.WithDeadline(ctx, GetNextSchedule(ctx))
135 defer cancel()
136 return innerRun(ctx)
137 }
138 return innerRun(ctx)
139 }
140 }
141}
142
143// Recover returns a new JobDescriptor that will recover from panics.
144func Recover(logger log.Logger) JobOption {

Callers 1

TestJobOptionFunction · 0.85

Calls 2

GetNextScheduleFunction · 0.85
IsZeroMethod · 0.80

Tested by 1

TestJobOptionFunction · 0.68