Skip to content
This repository was archived by the owner on Apr 30, 2023. It is now read-only.

Conversation

@cikupin
Copy link

@cikupin cikupin commented Oct 1, 2020

Re-PR this issue. Need review by maintainer.

What I fixed

  • Order & payment logic still executed even though compensatePurchaseItem had been executed. This means order & payment logic shouldn't be executed.
saga.AddSubTxDef(labelPurchaseItem, purchaseItemFailed, compensatePurchaseItem).
    AddSubTxDef(labelOrder, orderSuccess, compensateOrder).
    AddSubTxDef(labelPayment, paymentSuccess, compensatePayment)

ctx := context.Background()
property := &orderProperty{}
saga.StartSaga(ctx, sagaTopicID).
    ExecSub(labelPurchaseItem, property, input.Item).
    ExecSub(labelOrder, property, input.Item, input.Price).
    ExecSub(labelPayment, property, input.PaymentMethod, input.Price).
    EndSaga()
  • Add IsAborted() function to detect whether saga is complete or aborted.

Example:

sagaInstance := saga.StartSaga(ctx, sagaTopicID).
    ExecSub(labelPurchaseItem, property, input.Item).
    ExecSub(labelOrder, property, input.Item, input.Price).
    ExecSub(labelPayment, property, input.PaymentMethod, input.Price).
    EndSaga()

if sagaInstance.IsAborted() {
    // do something if saga is aborted
}

This change is Reviewable

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant