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 }