@@ -62,7 +62,7 @@ func ConsumeQueue() error {
62
62
// Process incoming messages
63
63
for msg := range msgs {
64
64
productID := string (msg .Body )
65
- log .Printf ("Received product_id: %s" )
65
+ log .Info ("Received product_id:" , productID )
66
66
i , err := strconv .Atoi (productID )
67
67
if err != nil {
68
68
log .Fatal (err )
@@ -76,7 +76,7 @@ func ConsumeQueue() error {
76
76
}
77
77
78
78
func processImages (productID int ) error {
79
- log .Info ("Found: :" , productID )
79
+ log .Info ("ProductID :" , productID )
80
80
collection := datab .ConnectToMongoDB ().Collection ("product-service-db" )
81
81
ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
82
82
defer cancel ()
@@ -93,15 +93,21 @@ func processImages(productID int) error {
93
93
}
94
94
replacement := bson.M {
95
95
"product_id" : productID ,
96
+ "product_name" : resp .ProductName ,
97
+ "product_description" : resp .ProductDescription ,
98
+ "product_images" : resp .ProductImages ,
99
+ "product_price" : resp .ProductPrice ,
96
100
"compressed_product_images" : resp .CompressedProductImages ,
101
+ "created_at" : time .Now (),
102
+ "updated_at" : time .Now (),
97
103
}
98
104
// replaceone ::
99
105
result , err := collection .ReplaceOne (ctx , filter , replacement )
100
106
if err != nil {
101
107
log .Info ("Error Found" , err )
102
108
}
103
109
if result .MatchedCount == 1 {
104
- log .Info ("Replace Sucessfully:: " )
110
+ log .Info ("Compressed Image Path Updated " )
105
111
} else {
106
112
log .Info ("Not Replaced::" )
107
113
return err
@@ -120,13 +126,7 @@ func saveImageLocally(image string) error {
120
126
}
121
127
defer resp .Body .Close ()
122
128
123
- if resp .StatusCode != http .StatusOK {
124
- log .Info ("HTTP request failed with status: %s\n " , resp .Status )
125
- return nil
126
- }
127
-
128
129
fileName := filepath .Base (imageURL )
129
-
130
130
err = os .MkdirAll (localDirectory , os .ModePerm )
131
131
if err != nil {
132
132
log .Info ("Failed to create local directory:" , err )
@@ -146,7 +146,6 @@ func saveImageLocally(image string) error {
146
146
log .Info ("Failed to save image to the local file:" , err )
147
147
return nil
148
148
}
149
-
150
- log .Info ("Image downloaded and saved as %s in directory %s\n " , fileName , localDirectory )
149
+ log .Info ("Path:" , localDirectory + imageURL )
151
150
return nil
152
151
}
0 commit comments