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

Function SkipIfOverlap

cron/options.go:95–111  ·  view source on GitHub ↗

SkipIfOverlap returns a new JobDescriptor that will skip the job if it overlaps with another job.

()

Source from the content-addressed store, hash-verified

93
94// SkipIfOverlap returns a new JobDescriptor that will skip the job if it overlaps with another job.
95func SkipIfOverlap() JobOption {
96 ch := make(chan struct{}, 1)
97 return func(descriptor *JobDescriptor) {
98 innerRun := descriptor.Run
99 descriptor.Run = func(ctx context.Context) error {
100 select {
101 case ch <- struct{}{}:
102 defer func() {
103 <-ch
104 }()
105 return innerRun(ctx)
106 default:
107 return errors.New("skipped due to overlap")
108 }
109 }
110 }
111}
112
113// DelayIfOverlap returns a new JobDescriptor that will delay the job if it overlaps with another job.
114func DelayIfOverlap() JobOption {

Callers 1

TestJobOptionFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestJobOptionFunction · 0.68