add listener and remove memory inventory service
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"git.tornberg.me/go-cart-actor/pkg/inventory"
|
||||
"github.com/redis/go-redis/v9"
|
||||
@@ -24,6 +25,18 @@ func main() {
|
||||
log.Fatalf("Unable to connect to inventory redis: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Start inventory change listener
|
||||
listener := inventory.NewInventoryChangeListener(rdb, ctx, func(changes []inventory.InventoryChange) {
|
||||
for _, change := range changes {
|
||||
log.Printf("Inventory change detected: SKU %s at location %s now has %d", change.SKU, change.StockLocationID, change.Value)
|
||||
}
|
||||
})
|
||||
log.Println("Starting inventory change listener...")
|
||||
go listener.Start()
|
||||
listener.WaitReady()
|
||||
log.Println("Listener is ready, proceeding with inventory operations...")
|
||||
|
||||
rdb.Pipelined(ctx, func(p redis.Pipeliner) error {
|
||||
s.UpdateInventory(p, "1", "1", 10)
|
||||
s.UpdateInventory(p, "2", "2", 20)
|
||||
@@ -51,4 +64,6 @@ func main() {
|
||||
}
|
||||
log.Printf("Inventory after reservation: %v", v)
|
||||
|
||||
// Wait a bit for listener to process messages
|
||||
time.Sleep(2 * time.Second)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user