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

Update readme

This commit is contained in:
Ken Hibino 2021-11-06 06:38:36 -07:00
parent f4ddac4dcc
commit 6bb4818509

View File

@ -103,7 +103,8 @@ func NewImageResizeTask(src string) (*asynq.Task, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return asynq.NewTask(TypeImageResize, payload), nil // task options can be passed to NewTask, which can be overridden at enqueue time.
return asynq.NewTask(TypeImageResize, payload, asynq.MaxRetry(5), asynq.Timeout(20 * time.Minute)), nil
} }
//--------------------------------------------------------------- //---------------------------------------------------------------
@ -196,24 +197,11 @@ func main() {
// Options include MaxRetry, Queue, Timeout, Deadline, Unique etc. // Options include MaxRetry, Queue, Timeout, Deadline, Unique etc.
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
client.SetDefaultOptions(tasks.TypeImageResize, asynq.MaxRetry(10), asynq.Timeout(3*time.Minute))
task, err = tasks.NewImageResizeTask("https://example.com/myassets/image.jpg") task, err = tasks.NewImageResizeTask("https://example.com/myassets/image.jpg")
if err != nil { if err != nil {
log.Fatalf("could not create task: %v", err) log.Fatalf("could not create task: %v", err)
} }
info, err = client.Enqueue(task) info, err = client.Enqueue(task, asynq.MaxRetry(10), asynq.Timeout(3 * time.Minute))
if err != nil {
log.Fatalf("could not enqueue task: %v", err)
}
log.Printf("enqueued task: id=%s queue=%s", info.ID, info.Queue)
// ---------------------------------------------------------------------------
// Example 4: Pass options to tune task processing behavior at enqueue time.
// Options passed at enqueue time override default ones.
// ---------------------------------------------------------------------------
info, err = client.Enqueue(task, asynq.Queue("critical"), asynq.Timeout(30*time.Second))
if err != nil { if err != nil {
log.Fatalf("could not enqueue task: %v", err) log.Fatalf("could not enqueue task: %v", err)
} }