Documentation
¶
Index ¶
Examples ¶
- Engine (Handle)
- Engine.New
- Engine.Register
- NewEngine
- TCC (CancelRetry)
- TCC (CancelRetry_concurrently)
- TCC (ConfirmOrCancel)
- TCC (ConfirmRetry)
- TCC (ConfirmRetry_concurrently)
- TCC (Fail)
- TCC (Fail_concurrent)
- TCC (StatusError)
- TCC (Success)
- TCC (Success_concurrent)
- TCC (Update)
- TCC.Cancel
- TCC.Confirm
- TCC.Try
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Example (Handle) ¶
fmt.Println(tccEngine.handle(nil, nil, &sqlmq.StdMessage{ Data: []byte{}, })) fmt.Println(tccEngine.handle(nil, nil, &sqlmq.StdMessage{ Data: []byte(`{"Status": "confirmed", "Actions":[{"Name":"test-action"}]}`), })) fmt.Println(tccEngine.handle(nil, nil, &sqlmq.StdMessage{ Data: []byte(`{"Status": "canceled", "Actions":[{"Name":"action1","Raw":1}]}`), })) fmt.Println(tccEngine.handle(nil, nil, &sqlmq.StdMessage{ Data: []byte(`{"Status": "confirmed", "Concurrent": true, "Actions":[{"Name":"test-action"}]}`), })) fmt.Println(tccEngine.handle(nil, nil, &sqlmq.StdMessage{ Data: []byte(`{"Status": "canceled", "Concurrent": true, "Actions":[{"Name":"action1","Raw":1}]}`), }))
Output: 1h0m0s true unexpected end of JSON input 1h0m0s true test-action: action not registered 1h0m0s true action1: json: cannot unmarshal number into Go value of type tcc.testAction1 1h0m0s true test-action: action not registered 1h0m0s true action1: json: cannot unmarshal number into Go value of type tcc.testAction1
func NewEngine ¶
name must be unique for the same mq.
Example ¶
defer func() { fmt.Println(timePrefix.ReplaceAllString(recover().(string), "")) }() NewEngine("test", testMQ)
Output: queue tcc-test already registered
func (*Engine) New ¶
Example ¶
tccEngine.mqName = "tcc-test2" defer func() { tccEngine.mqName = "tcc-test" }() _, err := tccEngine.New(time.Second, true) fmt.Println(err) fmt.Println(tccEngine.Run(time.Second, true))
Output: unknown queue: tcc-test2 unknown queue: tcc-test2
type TCC ¶
type TCC struct {
// contains filtered or unexported fields
}
Example (CancelRetry) ¶
runTest(false, testAction1{}, testAction2{}, &testAction6{}) time.Sleep(4 * time.Second)
Output: action1 Try action2 Try action6 Try error happened action6 Cancel 1 action6 Cancel 2 action2 Cancel action1 Cancel
Example (CancelRetry_concurrently) ¶
runTest(true, testAction1{}, testAction2{}, &testAction7{}) time.Sleep(4 * time.Second)
Output: action1 Try action2 Try action7 Try error happened action2 Cancel action1 Cancel action7 Cancel 1 action7 Cancel 2
Example (ConfirmOrCancel) ¶
tx, err := testDB.Begin() if err != nil { panic(err) } fmt.Println((&TCC{msg: &sqlmq.StdMessage{Data: &tccData{}}}).confirmOrCancel(tx))
Output: 0s true tcc(0) is canceled, cann't Cancel
Example (ConfirmRetry) ¶
runTest(false, testAction1{}, testAction2{}, &testAction4{}) time.Sleep(4 * time.Second)
Output: action1 Try action2 Try action4 Try action1 Confirm action2 Confirm action4 Confirm 1 action4 Confirm 2
Example (ConfirmRetry_concurrently) ¶
runTest(true, testAction1{}, testAction2{}, &testAction5{}) time.Sleep(4 * time.Second)
Output: action1 Try action2 Try action5 Try action1 Confirm action2 Confirm action5 Confirm 1 action5 Confirm 2
Example (Fail) ¶
runTest(false, testAction1{}, testAction3{}, testAction2{})
Output: action1 Try action3 Try error happened action3 Cancel action1 Cancel
Example (Fail_concurrent) ¶
runTest(true, testAction1{}, testAction3{}, testAction2{})
Output: action1 Try action3 Try error happened action3 Cancel action1 Cancel
Example (StatusError) ¶
tcc, err := tccEngine.New(time.Minute, false) if err != nil { panic(err) } canCommit, err := tcc.statusError("confirm action", testDB) fmt.Println(canCommit, tccId.ReplaceAllString(err.Error(), "tcc(1)")) db := getDB() db.Close() fmt.Println(tcc.statusError("confirm action", db))
Output: true tcc(1) is trying, cann't confirm action false sql: database is closed
Example (Success) ¶
runTest(false, testAction1{}, testAction2{})
Output: action1 Try action2 Try action1 Confirm action2 Confirm
Example (Success_concurrent) ¶
runTest(true, testAction1{}, testAction2{})
Output: action1 Try action2 Try action1 Confirm action2 Confirm
Example (Update) ¶
tcc, err := tccEngine.New(time.Minute, false) if err != nil { panic(err) } fmt.Println(tcc.update("", statusTrying, "xx", testDB))
Output: false pq: syntax error at or near "WHERE"
func (*TCC) Cancel ¶
Example ¶
tcc, err := tccEngine.New(time.Minute, false) if err != nil { panic(err) } fmt.Println(tcc.Confirm()) fmt.Println(tccId.ReplaceAllString(tcc.Cancel().Error(), "tcc(1)"))
Output: <nil> tcc(1) is confirmed, cann't Cancel
func (*TCC) Confirm ¶
Example ¶
tcc, err := tccEngine.New(time.Minute, false) if err != nil { panic(err) } fmt.Println(tcc.Confirm()) fmt.Println(tccId.ReplaceAllString(tcc.Confirm().Error(), "tcc(1)"))
Output: <nil> tcc(1) is confirmed, cann't Confirm
func (*TCC) Try ¶
Example ¶
tcc, err := tccEngine.New(time.Minute, false) if err != nil { panic(err) } fmt.Println(tcc.Try(testAction{})) fmt.Println(tcc.Try(&testAction1{})) fmt.Println(tcc.Try(testAction1{Data: make(chan int)})) tcc.msg.Id = -9 fmt.Println(tcc.Try(testAction1{}))
Output: action test-action is not registered action action1 has been registered with type "tcc.testAction1", but tried with type "*tcc.testAction1" json: unsupported type: chan int tcc(-9) not exists
Click to show internal directories.
Click to hide internal directories.