From 133bb6c2c671340a413bc0a860397520a469fd8b Mon Sep 17 00:00:00 2001 From: Ken Hibino Date: Tue, 11 Feb 2020 21:59:46 -0800 Subject: [PATCH] Update docs for context and timeout --- README.md | 5 ++++- doc.go | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1e80312..4cf71d7 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,9 @@ func main() { // Use custom queue called "critical" err = client.Schedule(t1, time.Now(), asynq.Queue("critical")) + + // Use timeout to specify how long a task may run (Default is no limit) + err = client.Schedule(t1, time.Now(), asynq.Timeout(30 * time.Second)) } ``` @@ -94,7 +97,7 @@ func main() { // If ProcessTask return a non-nil error or panics, the task // will be retried after delay. type Handler interface { - ProcessTask(*Task) error + ProcessTask(context.Context, *asynq.Task) error } ``` diff --git a/doc.go b/doc.go index f56b5c4..a369fc1 100644 --- a/doc.go +++ b/doc.go @@ -45,7 +45,7 @@ Example of a type that implements the Handler interface. // ... } - func (h *TaskHandler) ProcessTask(task *asynq.Task) error { + func (h *TaskHandler) ProcessTask(ctx context.Context, task *asynq.Task) error { switch task.Type { case "send_email": id, err := task.Payload.GetInt("user_id")