2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-11-10 11:31:58 +08:00

Update docs for context and timeout

This commit is contained in:
Ken Hibino 2020-02-11 21:59:46 -08:00
parent 39459b4412
commit 133bb6c2c6
2 changed files with 5 additions and 2 deletions

View File

@ -57,6 +57,9 @@ func main() {
// Use custom queue called "critical" // Use custom queue called "critical"
err = client.Schedule(t1, time.Now(), asynq.Queue("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 // If ProcessTask return a non-nil error or panics, the task
// will be retried after delay. // will be retried after delay.
type Handler interface { type Handler interface {
ProcessTask(*Task) error ProcessTask(context.Context, *asynq.Task) error
} }
``` ```

2
doc.go
View File

@ -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 { switch task.Type {
case "send_email": case "send_email":
id, err := task.Payload.GetInt("user_id") id, err := task.Payload.GetInt("user_id")