update
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 35s
Build and Publish / BuildAndDeployArm64 (push) Successful in 3m45s

This commit is contained in:
matst80
2025-11-27 12:45:34 +01:00
parent c2a137d8d4
commit aea168160e
14 changed files with 335 additions and 335 deletions

View File

@@ -22,7 +22,6 @@ import (
"go.opentelemetry.io/contrib/bridges/otelslog"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/timestamppb"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
@@ -80,10 +79,7 @@ func (s *PoolServer) AddSkuToCartHandler(w http.ResponseWriter, r *http.Request,
if err != nil {
return err
}
err = s.HandleReservations(r.Context(), id, msg)
if err != nil {
return err
}
data, err := s.ApplyLocal(r.Context(), id, msg)
if err != nil {
return err
@@ -260,11 +256,6 @@ func (s *PoolServer) AddMultipleItemHandler(w http.ResponseWriter, r *http.Reque
msgs := getMultipleAddMessages(r.Context(), setCartItems.Items, setCartItems.Country)
err = s.HandleReservations(r.Context(), id, msgs...)
if err != nil {
return err
}
reply, err := s.ApplyLocal(r.Context(), id, msgs...)
if err != nil {
return err
@@ -285,48 +276,6 @@ func (s *PoolServer) GetReservationTime(item *messages.AddItem) time.Duration {
//return nil
}
func (s *PoolServer) HandleReservations(ctx context.Context, cartId cart.CartId, msgs ...proto.Message) error {
if s.reservationService == nil {
return nil
}
for _, msg := range msgs {
item, ok := msg.(*messages.AddItem)
if !ok {
log.Printf("not an AddItem message, skipping reservation, was of type: %T", msg)
continue
}
timeout := s.GetReservationTime(item)
if timeout == 0 {
continue
}
span := trace.SpanFromContext(ctx)
locationId := inventory.LocationID("se")
if item.StoreId != nil {
locationId = inventory.LocationID(*item.StoreId)
}
span.AddEvent("reserving item", trace.WithAttributes(attribute.String("sku", item.Sku), attribute.String("locationId", string(locationId))))
log.Printf("reserving item %s at location %s for cart %s", item.Sku, string(locationId), cartId.String())
end := time.Now().Add(timeout)
err := s.reservationService.ReserveForCart(ctx, inventory.CartReserveRequest{
CartID: inventory.CartID(cartId.String()),
InventoryReference: &inventory.InventoryReference{
LocationID: locationId,
SKU: inventory.SKU(item.Sku),
},
Quantity: uint32(item.Quantity),
TTL: 15 * time.Minute,
})
if err != nil {
return err
}
logger.InfoContext(ctx, "reserved item", "sku", item.Sku, "location", string(locationId), "expires at", end.String())
span.End()
item.ReservationEndTime = timestamppb.New(end)
}
return nil
}
func (s *PoolServer) AddSkuRequestHandler(w http.ResponseWriter, r *http.Request, id cart.CartId) error {
addRequest := AddRequest{Quantity: 1}
err := json.NewDecoder(r.Body).Decode(&addRequest)
@@ -337,10 +286,7 @@ func (s *PoolServer) AddSkuRequestHandler(w http.ResponseWriter, r *http.Request
if err != nil {
return err
}
err = s.HandleReservations(r.Context(), id, msg)
if err != nil {
return err
}
reply, err := s.ApplyLocal(r.Context(), id, msg)
if err != nil {
return err