@@ -2,6 +2,7 @@ package main
22
33import (
44 "context"
5+ "flag"
56 "fmt"
67 "log"
78 "math/rand"
@@ -15,16 +16,20 @@ import (
1516
1617const ns = "taskqueue"
1718
19+ var redisAddr = flag .String ("redis-addr" , ":6379" , "Redis address" )
20+
1821func main () {
19- rc := redis .NewClient (& redis.Options {Addr : ":6379" })
22+ flag .Parse ()
23+
24+ rc := redis .NewClient (& redis.Options {Addr : * redisAddr })
2025
2126 enq := redisq .NewQueue (rc , redisq .WithNamespace (ns ))
2227
23- n1 := queuePaymentJob (enq )
24- n2 := queueEmailJob (enq )
28+ n1 := queueEmailJob (enq )
29+ n2 := queuePaymentJob (enq )
2530 n3 := queueNotificationJob (enq )
2631
27- fmt .Println ("Jobs Enqueued" , "payment " , n1 , "email " , n2 , "notification" , n3 )
32+ fmt .Println ("Jobs Enqueued" , "email " , n1 , "payment " , n2 , "notification" , n3 , "total" , n1 + n2 + n3 )
2833}
2934
3035func queueNotificationJob (enq taskqueue.Enqueuer ) int {
@@ -55,15 +60,21 @@ func queueNotificationJob(enq taskqueue.Enqueuer) int {
5560 return count
5661}
5762
63+ type paymentPayload struct {
64+ Gateway string `json:"gateway"`
65+ Amount int `json:"amount"`
66+ WalletID int `json:"wallet_id"`
67+ }
68+
5869func queuePaymentJob (enq taskqueue.Enqueuer ) int {
5970 count := rand .Intn (100 ) + 100
6071
6172 for i := range count {
6273 paymentJob := taskqueue .NewJob ()
63- _ = paymentJob .JSONMarshalPayload (map [ string ] interface {} {
64- "gateway" : "razorpay" ,
65- "amount" : 500 + i ,
66- "wallet_id" : "1" ,
74+ _ = paymentJob .JSONMarshalPayload (paymentPayload {
75+ Gateway : "razorpay" ,
76+ Amount : rand . Intn ( 1000 ) + 10000 ,
77+ WalletID : i ,
6778 })
6879 if err := enq .Enqueue (context .Background (), paymentJob , & taskqueue.EnqueueOptions {
6980 QueueName : "payment_queue" ,
0 commit comments