From 04702ddfd2fb243be2b10e94b67efd94a2730a58 Mon Sep 17 00:00:00 2001 From: Ken Hibino Date: Sat, 4 Jul 2020 05:24:47 -0700 Subject: [PATCH] Change ErrorHandler function signature --- CHANGELOG.md | 6 ++++-- processor.go | 2 +- processor_test.go | 2 +- server.go | 10 +++++----- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 622d36e..07459ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,9 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - All tasks now requires timeout or deadline. By default, timeout is set to 30 mins. - Tasks that exceed its deadline are automatically retried. -- Encoding schema for task message has changed. Please install the lastest CLI and run `migrate` command if - you have tasks enqueued by the previous version of asynq. +- Encoding schema for task message has changed. Please install the latest CLI and run `migrate` command if + you have tasks enqueued with the previous version of asynq. - API of `(*Client).Enqueue`, `(*Client).EnqueueIn`, and `(*Client).EnqueueAt` has changed to return a `*Result`. +- API of `ErrorHandler` has changed. It now takes context as the first argument and removed `retried`, `maxRetry` from the argument list. + Use `GetRetryCount` and/or `GetMaxRetry` to get the count values. ## [0.9.4] - 2020-06-13 diff --git a/processor.go b/processor.go index 459b64d..35960fa 100644 --- a/processor.go +++ b/processor.go @@ -212,7 +212,7 @@ func (p *processor) exec() { // 3) Kill -> Removes the message from InProgress & Adds the message to Dead if resErr != nil { if p.errHandler != nil { - p.errHandler.HandleError(task, resErr, msg.Retried, msg.Retry) + p.errHandler.HandleError(ctx, task, resErr) } p.retryOrKill(ctx, msg, resErr) return diff --git a/processor_test.go b/processor_test.go index 0b7183b..2d7aa2a 100644 --- a/processor_test.go +++ b/processor_test.go @@ -257,7 +257,7 @@ func TestProcessorRetry(t *testing.T) { mu sync.Mutex // guards n n int // number of times error handler is called ) - errHandler := func(t *Task, err error, retried, maxRetry int) { + errHandler := func(ctx context.Context, t *Task, err error) { mu.Lock() defer mu.Unlock() n++ diff --git a/server.go b/server.go index 95e7ee3..d52e2fa 100644 --- a/server.go +++ b/server.go @@ -127,16 +127,16 @@ type Config struct { // An ErrorHandler handles errors returned by the task handler. type ErrorHandler interface { - HandleError(task *Task, err error, retried, maxRetry int) + HandleError(ctx context.Context, task *Task, err error) } // The ErrorHandlerFunc type is an adapter to allow the use of ordinary functions as a ErrorHandler. // If f is a function with the appropriate signature, ErrorHandlerFunc(f) is a ErrorHandler that calls f. -type ErrorHandlerFunc func(task *Task, err error, retried, maxRetry int) +type ErrorHandlerFunc func(ctx context.Context, task *Task, err error) -// HandleError calls fn(task, err, retried, maxRetry) -func (fn ErrorHandlerFunc) HandleError(task *Task, err error, retried, maxRetry int) { - fn(task, err, retried, maxRetry) +// HandleError calls fn(ctx, task, err) +func (fn ErrorHandlerFunc) HandleError(ctx context.Context, task *Task, err error) { + fn(ctx, task, err) } // Logger supports logging at various log levels.