2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-09-20 19:06:46 +08:00
asynq/doc.go

46 lines
1.2 KiB
Go
Raw Normal View History

2019-12-06 22:12:44 +08:00
/*
Package asynq provides a framework for background task processing.
The Client is used to register a task to be processed at the specified time.
client := asynq.NewClient(redis)
2019-12-06 22:12:44 +08:00
t := &asynq.Task{
Type: "send_email",
Payload: map[string]interface{}{"recipient_id": 123},
}
err := client.Process(t, time.Now().Add(10 * time.Minute))
The Background is used to run the background processing with a given
handler with the specified number of workers.
bg := asynq.NewBackground(redis, &asynq.Config{
Concurrency: 20,
2019-12-06 22:12:44 +08:00
})
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.
type TaskHandler struct {
// ...
}
func (h *TaskHandler) ProcessTask(task *asynq.Task) error {
switch task.Type {
case "send_email":
// send email logic
case "generate_thumbnail":
// generate thumbnail image
//...
default:
return fmt.Errorf("unepected task type %q", task.Type)
}
return nil
}
*/
package asynq