start listener
This commit is contained in:
@@ -43,9 +43,10 @@ var (
|
||||
|
||||
type PoolServer struct {
|
||||
actor.GrainPool[*cart.CartGrain]
|
||||
pod_name string
|
||||
klarnaClient *KlarnaClient
|
||||
inventoryService inventory.InventoryService
|
||||
pod_name string
|
||||
klarnaClient *KlarnaClient
|
||||
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 {
|
||||
@@ -55,7 +56,7 @@ func NewPoolServer(pool actor.GrainPool[*cart.CartGrain], pod_name string, klarn
|
||||
klarnaClient: klarnaClient,
|
||||
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 {
|
||||
srv.GrainPool.GetPubSub().Publish(actor.Event{
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user