mirror of
https://github.com/hibiken/asynq.git
synced 2024-12-24 06:42:16 +08:00
Update package doc
This commit is contained in:
parent
c62833540c
commit
9256fb6023
24
doc.go
24
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
|
||||
//...
|
||||
|
Loading…
Reference in New Issue
Block a user