forked from goffee/cup
add base queue system
This commit is contained in:
parent
d431963181
commit
d413d7def4
7 changed files with 141 additions and 0 deletions
39
workers/workers.go
Normal file
39
workers/workers.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package workers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
"github.com/hibiken/asynq"
|
||||
)
|
||||
|
||||
// A list of task types.
|
||||
const (
|
||||
TypeWelcomeEmail = "email:welcome"
|
||||
TypeReminderEmail = "email:reminder"
|
||||
)
|
||||
|
||||
// Task payload for any email related tasks.
|
||||
type EmailTaskPayload struct {
|
||||
// ID for the email recipient.
|
||||
UserID int
|
||||
}
|
||||
|
||||
func HandleWelcomeEmailTask(ctx context.Context, t *asynq.Task) error {
|
||||
var p EmailTaskPayload
|
||||
if err := json.Unmarshal(t.Payload(), &p); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Printf(" [*] Send Welcome Email to User %d", p.UserID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func HandleReminderEmailTask(ctx context.Context, t *asynq.Task) error {
|
||||
var p EmailTaskPayload
|
||||
if err := json.Unmarshal(t.Payload(), &p); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Printf(" [*] Send Reminder Email to User %d", p.UserID)
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue