Skip to content

Commit 7d64c8b

Browse files
authored
Merge pull request #2 from cikupin/fix/action-after-compensation
add IsAbort() function
2 parents 40b3691 + 1340ef1 commit 7d64c8b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

saga.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (s *Saga) startSaga() {
6060
// ExecSub executes a sub-transaction for given subTxID(which define in SEC initialize) and arguments.
6161
// it returns current Saga.
6262
func (s *Saga) ExecSub(subTxID string, args ...interface{}) *Saga {
63-
if s.abortStatus {
63+
if s.IsAborted() {
6464
return s
6565
}
6666

@@ -100,7 +100,7 @@ func (s *Saga) ExecSub(subTxID string, args ...interface{}) *Saga {
100100
}
101101

102102
// EndSaga finishes a Saga's execution.
103-
func (s *Saga) EndSaga() {
103+
func (s *Saga) EndSaga() *Saga {
104104
log := &Log{
105105
Type: SagaEnd,
106106
Time: time.Now(),
@@ -113,6 +113,13 @@ func (s *Saga) EndSaga() {
113113
if err != nil {
114114
panic("Clean up topic failure")
115115
}
116+
117+
return s
118+
}
119+
120+
// IsAborted return status if saga is aborted or not
121+
func (s *Saga) IsAborted() bool {
122+
return s.abortStatus
116123
}
117124

118125
// Abort stop and compensate to rollback to start situation.

0 commit comments

Comments
 (0)