Documentation ¶
Index ¶
- func IsDeadlock(err error) bool
- func IsDup(err error) bool
- func IsNotFound(err error) bool
- func Run(ctx context.Context, db *sql.DB, fn func(context.Context) error) (err error)
- func RunInTx(ctx context.Context, db *sql.DB, fn func(context.Context, *sql.Tx) error) (err error)
- func RunInTxWithRetry(ctx context.Context, db *sql.DB, fn func(context.Context, *sql.Tx) error, ...) (err error)
- func RunInTxWithRetryBackoff(ctx context.Context, db *sql.DB, fn func(context.Context, *sql.Tx) error, ...) (err error)
- func RunWithRetry(ctx context.Context, db *sql.DB, fn func(context.Context) error, ...) (err error)
- func RunWithRetryBackoff(ctx context.Context, db *sql.DB, fn func(context.Context) error, ...) (err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsDeadlock ¶
IsDeadlock returns true if the given error indicates that we found a deadlock.
func IsNotFound ¶
IsNotFound returns true if the given error indicates that a record could not be found.
func RunInTx ¶
RunInTx runs fn in a database transaction. The context ctx is passed to fn, as well as the newly created transaction. If fn fails, it is repeated several times before giving up, with exponential backoff.
There are a few rules that fn must respect:
- fn must use the passed tx reference for all database calls.
- fn must not commit or rollback the transaction: Run will do that.
- fn must be idempotent, i.e. it may be called several times without side effects.
If fn returns nil, RunInTx commits the transaction, returning the Commit and a nil error if it succeeds.
If fn returns a non-nil value, RunInTx rolls back the transaction and will return the reported error from fn.
RunInTx also recovers from panics, e.g. in fn.
func RunInTxWithRetry ¶
func RunInTxWithRetry(ctx context.Context, db *sql.DB, fn func(context.Context, *sql.Tx) error, retryable func(error) bool) (err error)
RunInTxWithRetry is like RunInTx but will retry several times with exponential backoff. In that case, fn must also be idempotent, i.e. it may be called several times without side effects.
func RunInTxWithRetryBackoff ¶
func RunInTxWithRetryBackoff(ctx context.Context, db *sql.DB, fn func(context.Context, *sql.Tx) error, retryable func(error) bool, b backoff.BackOff) (err error)
RunInTxWithRetryBackoff is like RunInTxWithRetry but with configurable backoff.
func RunWithRetry ¶
Types ¶
This section is empty.