Skip to content

Commit

Permalink
Make retry handler nil safe (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
cameron-dunn-sublime authored Aug 15, 2023
1 parent 504fbae commit f9ce7c7
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions v1/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,26 +214,34 @@ func (worker *Worker) Process(signature *tasks.Signature, extendFunc tasks.Exten
// retry the task after specified duration
retryTaskLaterErr, ok := interface{}(err).(tasks.ErrRetryTaskLater)
if ok {
worker.taskRetryErrorHandler(err, signature)
if worker.taskRetryErrorHandler != nil {
worker.taskRetryErrorHandler(err, signature)
}
return worker.retryTaskIn(signature, retryTaskLaterErr.RetryIn())
}

keepAndRetryErr, ok := interface{}(err).(tasks.ErrKeepAndRetryTaskLater)
if ok {
worker.taskRetryErrorHandler(err, signature)
if worker.taskRetryErrorHandler != nil {
worker.taskRetryErrorHandler(err, signature)
}
return worker.keepAndRetryTaskIn(signature, keepAndRetryErr.RetryIn())
}

// Allow tasks to use errs.ErrStopTaskDeletion
if errors.Is(err, errs.ErrStopTaskDeletion) {
worker.taskRetryErrorHandler(err, signature)
if worker.taskRetryErrorHandler != nil {
worker.taskRetryErrorHandler(err, signature)
}
return err
}

// Otherwise, execute default retry logic based on signature.RetryCount
// and signature.RetryTimeout values
if signature.RetryCount > 0 {
worker.taskRetryErrorHandler(err, signature)
if worker.taskRetryErrorHandler != nil {
worker.taskRetryErrorHandler(err, signature)
}
return worker.taskRetry(signature)
}

Expand Down

0 comments on commit f9ce7c7

Please sign in to comment.