mirror of
https://github.com/hibiken/asynq.git
synced 2024-12-25 23:32:17 +08:00
Change ErrorHandler function signature
This commit is contained in:
parent
34b90ecc8a
commit
8d43fe407a
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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++
|
||||
|
10
server.go
10
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.
|
||||
|
Loading…
Reference in New Issue
Block a user