From 007fac8055231936d10265e03d758c408f6827cf Mon Sep 17 00:00:00 2001 From: Ken Hibino Date: Sat, 4 Jul 2020 06:31:56 -0700 Subject: [PATCH] Invoke error handler when ctx.Done channel is closed --- processor.go | 3 +++ server.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/processor.go b/processor.go index 35960fa..6a97178 100644 --- a/processor.go +++ b/processor.go @@ -203,6 +203,9 @@ func (p *processor) exec() { return case <-ctx.Done(): p.logger.Debugf("Retrying task. task id=%s", msg.ID) // TODO: Improve this log message and above + if p.errHandler != nil { + p.errHandler.HandleError(ctx, task, ctx.Err()) + } p.retryOrKill(ctx, msg, ctx.Err()) return case resErr := <-resCh: diff --git a/server.go b/server.go index d52e2fa..3fc8998 100644 --- a/server.go +++ b/server.go @@ -125,7 +125,7 @@ type Config struct { ShutdownTimeout time.Duration } -// An ErrorHandler handles errors returned by the task handler. +// An ErrorHandler handles an error occured during task processing. type ErrorHandler interface { HandleError(ctx context.Context, task *Task, err error) }