start listener
This commit is contained in:
@@ -43,9 +43,10 @@ var (
|
|||||||
|
|
||||||
type PoolServer struct {
|
type PoolServer struct {
|
||||||
actor.GrainPool[*cart.CartGrain]
|
actor.GrainPool[*cart.CartGrain]
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user