Skip to content

Commit f6bf011

Browse files
committed
feat(saga):Add saga abort log
- add saga abort log - fix Readme.
1 parent a20a62f commit f6bf011

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# go-saga
22

3-
[![GoDoc](https://godoc.org/github.com/lysu/go-saga?status.svg)](https://godoc.org/github.com/lysu/go-saga)[![Build Status](https://travis-ci.org/lysu/go-saga.svg?branch=master)](https://travis-ci.org/lysu/go-saga)
3+
[![GoDoc](https://godoc.org/github.com/lysu/go-saga?status.svg)](https://godoc.org/github.com/lysu/go-saga)
4+
[![Build Status](https://travis-ci.org/lysu/go-saga.svg?branch=master)](https://travis-ci.org/lysu/go-saga)
45

56
Implements sagas-pattern in go, make distribute transaction easier.
67

log.go

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const (
1313
SagaStart LogType = iota + 1
1414
// SagaEnd flag saga ended log
1515
SagaEnd
16+
// SagaAbort flag saga aborted
17+
SagaAbort
1618
// ActionStart flag action start log
1719
ActionStart
1820
// ActionEnd flag action end log

saga.go

+8
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ func (s *Saga) Abort() {
8686
if err != nil {
8787
panic("Abort Panic")
8888
}
89+
alog := &Log{
90+
Type: SagaAbort,
91+
Time: time.Now(),
92+
}
93+
err = s.sec.logStorage.AppendLog(s.logID, alog.mustMarshal())
94+
if err != nil {
95+
panic("Add log Failure")
96+
}
8997
for i := len(logs) - 1; i >= 0; i-- {
9098
logData := logs[i]
9199
log := mustUnmarshalLog(logData)

saga_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func TestDepositFail(t *testing.T) {
7777
logs, err := storage.Lookup("saga_1")
7878
assert.NoError(t, err)
7979
t.Logf("%v", logs)
80-
assert.Equal(t, 9, len(logs))
80+
assert.Equal(t, 10, len(logs))
8181

8282
}
8383

0 commit comments

Comments
 (0)