From 9256fb60232c640f4a94ca369c3c25f1c4ad185f Mon Sep 17 00:00:00 2001 From: Ken Hibino Date: Thu, 2 Jan 2020 19:47:04 -0800 Subject: [PATCH] Update package doc --- doc.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/doc.go b/doc.go index 8d2ab89..21ceb5c 100644 --- a/doc.go +++ b/doc.go @@ -9,26 +9,27 @@ The Client is used to register a task to be processed at the specified time. client := asynq.NewClient(redis) - t := &asynq.Task{ + t := asynq.Task{ Type: "send_email", - Payload: map[string]interface{}{"recipient_id": 123}, + Payload: map[string]interface{}{"user_id": 42}, } - err := client.Process(t, time.Now().Add(10 * time.Minute)) + err := client.Process(&t, time.Now().Add(time.Minute)) -The Background is used to run the background processing with a given -handler with the specified number of workers. +The Background is used to run the background task processing with a given +handler. bg := asynq.NewBackground(redis, &asynq.Config{ - Concurrency: 20, + Concurrency: 10, }) bg.Run(handler) -Handler is an interface that implements ProcessTask method that -takes a Task and return an error. Handler should return nil if -the processing is successful, otherwise return non-nil error -so that the task will be retried after some delay. +Handler is an interface with one method ProcessTask which +takes a task and returns an error. Handler should return nil if +the processing is successful, otherwise return a non-nil error. +If handler returns a non-nil error, the task will be retried in the future. +Example of a type that implements the Handler interface. type TaskHandler struct { // ... } @@ -36,7 +37,8 @@ so that the task will be retried after some delay. func (h *TaskHandler) ProcessTask(task *asynq.Task) error { switch task.Type { case "send_email": - // send email logic + id, err := task.Payload.GetInt("user_id") + // send email case "generate_thumbnail": // generate thumbnail image //...