dbretry

package
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2023 License: Apache-2.0 Imports: 6 Imported by: 3

Documentation

Overview

Package dbretry contains structs that implement various db interfaces as well as consume them. They allow consumers to easily try to interact with the database a configurable number of times, with configurable backoff options and metrics.

Index

Constants

View Source
const (
	SQLQueryRetryCounter = "sql_query_retry_count"
	SQLQueryEndCounter   = "sql_query_end_counter"
)

Variables

This section is empty.

Functions

func Metrics

func Metrics() []xmetrics.Metric

Metrics returns the Metrics relevant to this package

Types

type Measures

type Measures struct {
	SQLQueryRetryCount metrics.Counter
	SQLQueryEndCount   metrics.Counter
}

func NewMeasures

func NewMeasures(p provider.Provider) Measures

type Option

type Option func(r *retryConfig)

Option is the function used to configure the retry object.

func WithBackoff added in v0.4.0

func WithBackoff(b backoff.ExponentialBackOff) Option

WithBackoff sets the exponential backoff to use when retrying. If this isn't called, we use the backoff package's default ExponentialBackoff configuration. If any values are considered invalid, they are replaced with those defaults.

func WithMeasures

func WithMeasures(p provider.Provider) Option

WithMeasures sets a provider to use for metrics.

type RetryInsertService

type RetryInsertService struct {
	// contains filtered or unexported fields
}

RetryInsertService is a wrapper for a db.Inserter. If inserting fails, the retry service will continue to try until the configurable max elapsed time is reached. The retries will exponentially backoff in the manner configured. To read more about this, see the backoff package GoDoc: https://godoc.org/gopkg.in/cenkalti/backoff.v3

func CreateRetryInsertService

func CreateRetryInsertService(inserter db.Inserter, options ...Option) RetryInsertService

CreateRetryInsertService takes an inserter and the options provided and creates a RetryInsertService.

func (RetryInsertService) AddRetryMetric added in v0.4.0

func (ri RetryInsertService) AddRetryMetric(_ error, _ time.Duration)

AddRetryMetric is a function to add to our metrics when we retry. The function is passed to the backoff package and is called when we are retrying.

func (RetryInsertService) InsertRecords

func (ri RetryInsertService) InsertRecords(records ...db.Record) error

InsertRecords uses the inserter to insert the records and uses the ExponentialBackoff to try again if inserting fails.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL