more otel
This commit is contained in:
@@ -84,10 +84,13 @@ func main() {
|
||||
|
||||
reg := cart.NewCartMultationRegistry()
|
||||
reg.RegisterProcessor(
|
||||
actor.NewMutationProcessor(func(g *cart.CartGrain) error {
|
||||
actor.NewMutationProcessor(func(ctx context.Context, g *cart.CartGrain) error {
|
||||
_, span := tracer.Start(ctx, "Totals and promotions")
|
||||
defer span.End()
|
||||
g.UpdateTotals()
|
||||
ctx := promotions.NewContextFromCart(g, promotions.WithNow(time.Now()), promotions.WithCustomerSegment("vip"))
|
||||
_, actions := promotionService.EvaluateAll(promotionData.State.Promotions, ctx)
|
||||
|
||||
promotionCtx := promotions.NewContextFromCart(g, promotions.WithNow(time.Now()), promotions.WithCustomerSegment("vip"))
|
||||
_, actions := promotionService.EvaluateAll(promotionData.State.Promotions, promotionCtx)
|
||||
for _, action := range actions {
|
||||
log.Printf("apply: %+v", action)
|
||||
g.UpdateTotals()
|
||||
@@ -100,12 +103,14 @@ func main() {
|
||||
poolConfig := actor.GrainPoolConfig[cart.CartGrain]{
|
||||
MutationRegistry: reg,
|
||||
Storage: diskStorage,
|
||||
Spawn: func(id uint64) (actor.Grain[cart.CartGrain], error) {
|
||||
Spawn: func(ctx context.Context, id uint64) (actor.Grain[cart.CartGrain], error) {
|
||||
_, span := tracer.Start(ctx, fmt.Sprintf("Spawn cart id %d", id))
|
||||
defer span.End()
|
||||
grainSpawns.Inc()
|
||||
ret := cart.NewCartGrain(id, time.Now())
|
||||
// Set baseline lastChange at spawn; replay may update it to last event timestamp.
|
||||
|
||||
err := diskStorage.LoadEvents(id, ret)
|
||||
err := diskStorage.LoadEvents(ctx, id, ret)
|
||||
|
||||
return ret, err
|
||||
},
|
||||
@@ -249,7 +254,7 @@ func main() {
|
||||
|
||||
}
|
||||
|
||||
func triggerOrderCompleted(syncedServer *PoolServer, order *CheckoutOrder) error {
|
||||
func triggerOrderCompleted(ctx context.Context, syncedServer *PoolServer, order *CheckoutOrder) error {
|
||||
mutation := &messages.OrderCreated{
|
||||
OrderId: order.ID,
|
||||
Status: order.Status,
|
||||
@@ -258,12 +263,12 @@ func triggerOrderCompleted(syncedServer *PoolServer, order *CheckoutOrder) error
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid cart id in order reference: %s", order.MerchantReference1)
|
||||
}
|
||||
_, applyErr := syncedServer.Apply(uint64(cid), mutation)
|
||||
_, applyErr := syncedServer.Apply(ctx, uint64(cid), mutation)
|
||||
|
||||
return applyErr
|
||||
}
|
||||
|
||||
func confirmOrder(order *CheckoutOrder, orderHandler *AmqpOrderHandler) error {
|
||||
func confirmOrder(ctx context.Context, order *CheckoutOrder, orderHandler *AmqpOrderHandler) error {
|
||||
orderToSend, err := json.Marshal(order)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user