DelayIfOverlap returns a new JobDescriptor that will delay the job if it overlaps with another job.
()
| 112 | |
| 113 | // DelayIfOverlap returns a new JobDescriptor that will delay the job if it overlaps with another job. |
| 114 | func DelayIfOverlap() JobOption { |
| 115 | ch := make(chan struct{}, 1) |
| 116 | return func(descriptor *JobDescriptor) { |
| 117 | innerRun := descriptor.Run |
| 118 | descriptor.Run = func(ctx context.Context) error { |
| 119 | ch <- struct{}{} |
| 120 | defer func() { |
| 121 | <-ch |
| 122 | }() |
| 123 | return innerRun(ctx) |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | // TimeoutIfOverlap returns a new JobDescriptor that will cancel the job's context if the next schedule is due. |
| 129 | func TimeoutIfOverlap() JobOption { |
no outgoing calls