Add Get* methods to Payload type

This commit is contained in:
Ken Hibino
2019-12-19 07:13:43 -08:00
parent 3fd096a90a
commit 14ac5f6674
6 changed files with 418 additions and 7 deletions

View File

@@ -66,11 +66,11 @@ func main() {
func handler(t *asynq.Task) error {
switch t.Type {
case "send_welcome_email":
rid, ok := t.Payload["recipient_id"]
if !ok {
return fmt.Errorf("recipient_id not found in payload")
id, err := t.Payload.GetInt("recipient_id")
if err != nil{
return err
}
fmt.Printf("Send Welcome Email to %d\n", rid.(int))
fmt.Printf("Send Welcome Email to %d\n", id)
// ... handle other task types.