package main import ( "context" "log" "sync" "git.k6n.net/mats/go-redis-inventory/pkg/inventory" "git.k6n.net/mats/slask-finder/pkg/types" "github.com/redis/go-redis/v9" ) type StockHandler struct { rdb *redis.Client ctx context.Context svc inventory.RedisInventoryService MainStockLocationID inventory.LocationID } func (s *StockHandler) HandleItem(item types.Item, wg *sync.WaitGroup) { wg.Go(func() { ctx := s.ctx pipe := s.rdb.Pipeline() centralStock, ok := item.GetNumberFieldValue("inStock") if !ok { centralStock = 0 } sku, ok := item.GetStringFieldValue("sku") if !ok { log.Printf("unable to parse central stock for item: sku missing") centralStock = 0 } else { 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(sku), inventory.LocationID(id), int64(value)) // } _, err := pipe.Exec(ctx) if err != nil { log.Printf("unable to update stock: %v", err) } }) }