update
Some checks failed
Build and Publish / BuildAndDeployAmd64 (push) Failing after 27s
Build and Publish / BuildAndDeployArm64 (push) Failing after 3m10s

This commit is contained in:
2025-11-25 20:27:04 +01:00
parent ff8a332e3b
commit b0907aee41
2 changed files with 28 additions and 6 deletions

View File

@@ -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) {