SkipIfOverlap returns a new JobDescriptor that will skip the job if it overlaps with another job.
()
| 93 | |
| 94 | // SkipIfOverlap returns a new JobDescriptor that will skip the job if it overlaps with another job. |
| 95 | func 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. |
| 114 | func DelayIfOverlap() JobOption { |
no outgoing calls