From f9ce7c725883d6c6e2e7a804082ffab7e227046a Mon Sep 17 00:00:00 2001 From: Cameron Dunn Date: Tue, 15 Aug 2023 09:59:01 -0700 Subject: [PATCH] Make retry handler nil safe (#25) --- v1/worker.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/v1/worker.go b/v1/worker.go index 65baa67..dbe1dd4 100644 --- a/v1/worker.go +++ b/v1/worker.go @@ -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) }