You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
620 B

package daemon
import "context"
// Retry set retry job and change return after max retry.
func Retry(max uint8, handleRetry func(err error) error) Option {
var retry uint8
return func(j *Job) {
WithRunMiddleware(func(ctx context.Context, next Run) error {
if err := next(ctx); err != nil {
retry++
if retry >= max {
return handleRetry(err)
}
return err
}
retry = 0
return nil
})(j)
}
}
// RunOnce run once and stopped job.
func RunOnce() Option {
return func(j *Job) {
WithRunMiddleware(func(ctx context.Context, next Run) error {
return StopJob(next(ctx))
})(j)
}
}