update
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 34s
Build and Publish / BuildAndDeployArm64 (push) Successful in 3m52s

This commit is contained in:
2025-11-25 20:30:45 +01:00
parent b0907aee41
commit e7e572b0f7
2 changed files with 7 additions and 9 deletions

View File

@@ -145,7 +145,7 @@ func main() {
log.Fatalf("Error creating inventory service: %v\n", err)
}
syncedServer := NewPoolServer(pool, fmt.Sprintf("%s, %s", name, podIp), klarnaClient, inventoryService)
syncedServer := NewPoolServer(pool, fmt.Sprintf("%s, %s", name, podIp), klarnaClient, inventoryService, rdb)
app := &App{
pool: pool,

View File

@@ -55,15 +55,13 @@ func NewPoolServer(pool actor.GrainPool[*cart.CartGrain], pod_name string, klarn
klarnaClient: klarnaClient,
inventoryService: inventoryService,
}
inventory.NewInventoryChangeListener(inventoryRedisClient, func(ctx context.Context, sku inventory.SKU, locationID inventory.LocationID) {
qty, err := inventoryService.GetInventory(ctx, sku, locationID)
if err != nil {
log.Printf("error fetching inventory for sku %s at location %s: %v", sku, locationID, err)
inventory.NewInventoryChangeListener(inventoryRedisClient, context.Background(), func(changes []inventory.InventoryChange) {
for _, change := range changes {
srv.GrainPool.GetPubSub().Publish(actor.Event{
Topic: fmt.Sprintf("inventory:%s:%s", change.SKU, change.StockLocationID),
Payload: change.Value,
})
}
srv.GrainPool.GetPubSub().Publish(actor.Event{
Topic: fmt.Sprintf("inventory:%s:%s", sku, locationID),
Payload: qty,
})
})
return srv
}