TimeoutIfOverlap returns a new JobDescriptor that will cancel the job's context if the next schedule is due.
()
| 127 | |
| 128 | // TimeoutIfOverlap returns a new JobDescriptor that will cancel the job's context if the next schedule is due. |
| 129 | func 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. |
| 144 | func Recover(logger log.Logger) JobOption { |