2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-12-27 00:02:19 +08:00

Change ErrorHandler function signature

This commit is contained in:
Ken Hibino 2020-07-04 05:24:47 -07:00
parent 34b90ecc8a
commit 8d43fe407a
4 changed files with 11 additions and 9 deletions

View File

@ -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. - All tasks now requires timeout or deadline. By default, timeout is set to 30 mins.
- Tasks that exceed its deadline are automatically retried. - 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 - Encoding schema for task message has changed. Please install the latest CLI and run `migrate` command if
you have tasks enqueued by the previous version of asynq. 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 `(*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 ## [0.9.4] - 2020-06-13

View File

@ -212,7 +212,7 @@ func (p *processor) exec() {
// 3) Kill -> Removes the message from InProgress & Adds the message to Dead // 3) Kill -> Removes the message from InProgress & Adds the message to Dead
if resErr != nil { if resErr != nil {
if p.errHandler != 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) p.retryOrKill(ctx, msg, resErr)
return return

View File

@ -257,7 +257,7 @@ func TestProcessorRetry(t *testing.T) {
mu sync.Mutex // guards n mu sync.Mutex // guards n
n int // number of times error handler is called 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() mu.Lock()
defer mu.Unlock() defer mu.Unlock()
n++ n++

View File

@ -127,16 +127,16 @@ type Config struct {
// An ErrorHandler handles errors returned by the task handler. // An ErrorHandler handles errors returned by the task handler.
type ErrorHandler interface { 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. // 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. // 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) // HandleError calls fn(ctx, task, err)
func (fn ErrorHandlerFunc) HandleError(task *Task, err error, retried, maxRetry int) { func (fn ErrorHandlerFunc) HandleError(ctx context.Context, task *Task, err error) {
fn(task, err, retried, maxRetry) fn(ctx, task, err)
} }
// Logger supports logging at various log levels. // Logger supports logging at various log levels.