update
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/matst80/go-redis-inventory/pkg/inventory"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"go.opentelemetry.io/contrib/bridges/otelslog"
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
@@ -47,13 +48,24 @@ type PoolServer struct {
|
||||
inventoryService inventory.InventoryService
|
||||
}
|
||||
|
||||
func NewPoolServer(pool actor.GrainPool[*cart.CartGrain], pod_name string, klarnaClient *KlarnaClient, inventoryService inventory.InventoryService) *PoolServer {
|
||||
return &PoolServer{
|
||||
func NewPoolServer(pool actor.GrainPool[*cart.CartGrain], pod_name string, klarnaClient *KlarnaClient, inventoryService inventory.InventoryService, inventoryRedisClient *redis.Client) *PoolServer {
|
||||
srv := &PoolServer{
|
||||
GrainPool: pool,
|
||||
pod_name: pod_name,
|
||||
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)
|
||||
}
|
||||
srv.GrainPool.GetPubSub().Publish(actor.Event{
|
||||
Topic: fmt.Sprintf("inventory:%s:%s", sku, locationID),
|
||||
Payload: qty,
|
||||
})
|
||||
})
|
||||
return srv
|
||||
}
|
||||
|
||||
func (s *PoolServer) ApplyLocal(ctx context.Context, id cart.CartId, mutation ...proto.Message) (*actor.MutationResult[*cart.CartGrain], error) {
|
||||
|
||||
Reference in New Issue
Block a user