Documentation ¶
Overview ¶
Package transaction provides an interface for crafting transactional updates to consul.
Index ¶
- Variables
- func Add(ctx context.Context, op api.KVTxnOp) error
- func Commit(ctx context.Context, txner Txner) (bool, *api.KVTxnResponse, error)
- func CommitWithRetries(ctx context.Context, txner Txner) (bool, *api.KVTxnResponse, error)
- func MustCommit(ctx context.Context, txner Txner) error
- func New(ctx context.Context) (context.Context, context.CancelFunc)
- func TxnErrorsToString(errors api.TxnErrors) string
- type Txner
Constants ¶
This section is empty.
Variables ¶
var ( ErrTooManyOperations = errors.New("consul transactions cannot have more than 64 operations") ErrAlreadyCommitted = errors.New("this transaction has already been committed") )
Functions ¶
func Commit ¶
Commit attempts to run all of the kv operations in the context's transaction. The cancel function with which the context was created must also be passed to guarantee that the transaction won't be applied twice
func CommitWithRetries ¶
CommitWithRetries retries Commit() until the transaction is applied without an error. It will not retry the transaction if there is no error but the transaction was rolled back (and it wouldn't make sense to because it won't succeed after that point)
An exponential backoff strategy is used until the context is cancelled with a max backoff time of 10 seconds
func MustCommit ¶
MustCommit is a convenience wrapper for Commit that returns a single error if the transaction fails OR if the transaction is rolled back. If the caller wishes to take different action depending on if the transaction failed or was rolled back then Commit() should be used instead
func New ¶
New() returns a new context derived from the one passed as an argument and its cancel function with the context containing metadata used to build a consul transaction. If the passed context already has consul operations defined, the new context will inherit those operations defined but in a separate transaction.