start listener
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 34s
Build and Publish / BuildAndDeployArm64 (push) Successful in 3m43s

This commit is contained in:
2025-11-25 21:17:25 +01:00
parent 990708597b
commit 82650bd3dd

View File

@@ -46,6 +46,7 @@ type PoolServer struct {
pod_name string pod_name string
klarnaClient *KlarnaClient klarnaClient *KlarnaClient
inventoryService inventory.InventoryService inventoryService inventory.InventoryService
inventoryListener *inventory.InventoryChangeListener
} }
func NewPoolServer(pool actor.GrainPool[*cart.CartGrain], pod_name string, klarnaClient *KlarnaClient, inventoryService inventory.InventoryService, inventoryRedisClient *redis.Client) *PoolServer { func NewPoolServer(pool actor.GrainPool[*cart.CartGrain], pod_name string, klarnaClient *KlarnaClient, inventoryService inventory.InventoryService, inventoryRedisClient *redis.Client) *PoolServer {
@@ -55,7 +56,7 @@ func NewPoolServer(pool actor.GrainPool[*cart.CartGrain], pod_name string, klarn
klarnaClient: klarnaClient, klarnaClient: klarnaClient,
inventoryService: inventoryService, inventoryService: inventoryService,
} }
inventory.NewInventoryChangeListener(inventoryRedisClient, context.Background(), func(changes []inventory.InventoryChange) { listener := inventory.NewInventoryChangeListener(inventoryRedisClient, context.Background(), func(changes []inventory.InventoryChange) {
for _, change := range changes { for _, change := range changes {
srv.GrainPool.GetPubSub().Publish(actor.Event{ srv.GrainPool.GetPubSub().Publish(actor.Event{
Topic: fmt.Sprintf("inventory:%s", change.SKU), Topic: fmt.Sprintf("inventory:%s", change.SKU),
@@ -63,6 +64,8 @@ func NewPoolServer(pool actor.GrainPool[*cart.CartGrain], pod_name string, klarn
}) })
} }
}) })
srv.inventoryListener = listener
go listener.Start()
return srv return srv
} }