Skip to content

Commit

Permalink
feat(db): helper for setting retrier directly
Browse files Browse the repository at this point in the history
  • Loading branch information
arsham committed Mar 23, 2022
1 parent 7c20966 commit eca2010
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ type Tx interface {
// A ConfigFunc function sets up a Transaction.
type ConfigFunc func(*Transaction)

// Retry sets the retrier.
func Retry(r retry.Retry) ConfigFunc {
return func(t *Transaction) {
t.retries = r.Attempts
t.delay = r.Delay
t.method = r.Method
}
}

// RetryCount defines a transaction should be tried n times. If n is 0, it will
// be set as 1.
func RetryCount(n int) ConfigFunc {
Expand Down
1 change: 1 addition & 0 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestNewTransaction(t *testing.T) {
"sql.DB": {db, nil, nil},
"low attempts": {db, []dbtools.ConfigFunc{dbtools.RetryCount(-1)}, nil},
"delay method": {db, []dbtools.ConfigFunc{dbtools.DelayMethod(retry.IncrementalDelay)}, nil},
"retrier": {db, []dbtools.ConfigFunc{dbtools.Retry(retry.Retry{})}, nil},
}
for name, tc := range tcs {
tc := tc
Expand Down

0 comments on commit eca2010

Please sign in to comment.