update cart
Build and Publish / BuildAndDeployArm64 (push) Failing after 5s
Build and Publish / BuildAndDeployAmd64 (push) Has been cancelled

This commit is contained in:
2026-06-17 14:16:25 +02:00
parent 11be8aec56
commit ad410d217c
11 changed files with 257 additions and 41 deletions
+6 -12
View File
@@ -132,20 +132,14 @@ func main() {
}
// items listener
err = messaging.ListenToTopic(ch, country, "item_added", func(d amqp.Delivery) error {
var items []*index.DataItem
err := json.Unmarshal(d.Body, &items)
if err == nil {
log.Printf("Got upserts %d, message count %d", len(items), d.MessageCount)
wg := &sync.WaitGroup{}
for _, item := range items {
stockhandler.HandleItem(item, wg)
}
wg := &sync.WaitGroup{}
err = index.ForEachRawDataItemInJSONArray(d.Body, func(item *index.RawDataItem) error {
stockhandler.HandleItem(item, wg)
wg.Wait()
log.Print("Batch done...")
} else {
log.Printf("Failed to unmarshal upsert message %v", err)
}
return err
return err
})
return nil
})
if err != nil {
log.Fatalf("Failed to listen to item_added topic: %v", err)
+10 -15
View File
@@ -3,8 +3,6 @@ package main
import (
"context"
"log"
"strconv"
"strings"
"sync"
"git.k6n.net/mats/go-redis-inventory/pkg/inventory"
@@ -23,25 +21,22 @@ func (s *StockHandler) HandleItem(item types.Item, wg *sync.WaitGroup) {
wg.Go(func() {
ctx := s.ctx
pipe := s.rdb.Pipeline()
centralStockString, ok := item.GetStringFieldValue(3)
centralStock, ok := item.GetNumberFieldValue("inStock")
if !ok {
centralStockString = "0"
centralStock = 0
}
centralStockString = strings.Replace(centralStockString, "+", "", -1)
centralStockString = strings.Replace(centralStockString, "<", "", -1)
centralStockString = strings.Replace(centralStockString, ">", "", -1)
centralStock, err := strconv.ParseInt(centralStockString, 10, 64)
if err != nil {
log.Printf("unable to parse central stock for item %s: %v", item.GetSku(), err)
sku, ok := item.GetStringFieldValue("sku")
if !ok {
log.Printf("unable to parse central stock for item %s: %v", sku)
centralStock = 0
} else {
s.svc.UpdateInventory(ctx, pipe, inventory.SKU(item.GetSku()), s.MainStockLocationID, int64(centralStock))
s.svc.UpdateInventory(ctx, pipe, inventory.SKU(sku), s.MainStockLocationID, int64(centralStock))
}
for id, value := range item.GetStock() {
s.svc.UpdateInventory(ctx, pipe, inventory.SKU(item.GetSku()), inventory.LocationID(id), int64(value))
}
_, err = pipe.Exec(ctx)
// for id, value := range item.GetStock() {
// s.svc.UpdateInventory(ctx, pipe, inventory.SKU(sku), inventory.LocationID(id), int64(value))
// }
_, err := pipe.Exec(ctx)
if err != nil {
log.Printf("unable to update stock: %v", err)
}