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

Update readme

This commit is contained in:
Ken Hibino 2019-12-01 19:03:31 -08:00
parent 1a97d4ba98
commit 1a996e0d40

View File

@ -31,22 +31,22 @@ func main() {
t1 := &asynq.Task{ t1 := &asynq.Task{
Type: "send_welcome_email", Type: "send_welcome_email",
Payload: map[string]interface{ Payload: map[string]interface{}{
"recipient_id": 1234, "recipient_id": 1234,
}, },
} }
t2 := &asynq.Task{ t2 := &asynq.Task{
Type: "send_reminder_email", Type: "send_reminder_email",
Payload: map[string]interface{ Payload: map[string]interface{}{
"recipient_id": 1234, "recipient_id": 1234,
}, },
} }
// send welcome email now. // process the task immediately.
client.Process(t1, time.Now()) client.Process(t1, time.Now())
// send reminder email 24 hours later. // process the task 24 hours later.
client.Process(t2, time.Now().Add(24 * time.Hour)) client.Process(t2, time.Now().Add(24 * time.Hour))
} }
``` ```
@ -62,6 +62,7 @@ func main() {
bg.Run(handler) bg.Run(handler)
} }
// if handler returns an error or panics, the task will be retried after some delay.
func handler(t *Task) error { func handler(t *Task) error {
switch t.Type { switch t.Type {
case "send_welcome_email": case "send_welcome_email":