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 ¶
const ( SQLQueryRetryCounter = "sql_query_retry_count" SQLQueryEndCounter = "sql_query_end_counter" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Measures ¶
func NewMeasures ¶
type Option ¶
type Option func(r *retryConfig)
Option is the function used to configure the retry objects.
func WithInterval ¶
WithInterval sets the amount of time to wait between the initial attempt and the first retry. If the interval multiplier is 1, this interval is used between every attempt.
func WithIntervalMultiplier ¶
WithIntervalMultiplier sets the interval multiplier, which is multiplied against the interval time for each wait time after the first retry. For example, if the interval is 1s, the interval multiplier 5, and the number of retries 3, then between the initial attempt and first retry, the program will wait 1s. Between the first retry and the second retry, the program will wait 5s. Between the second retry and the third, the program will wait 25s. This is assuming all attempts fail.
func WithMeasures ¶
WithMeasures provides a provider to use for metrics.
func WithRetries ¶
WithRetries sets the number of times to potentially try to interact with the database if the inital attempt doesn't succeed.
type RetryInsertService ¶
type RetryInsertService struct {
// contains filtered or unexported fields
}
RetryInsertService is a wrapper for a db.Inserter that attempts to insert a configurable number of times if the inserts fail.
func CreateRetryInsertService ¶
func CreateRetryInsertService(inserter db.Inserter, options ...Option) RetryInsertService
CreateRetryInsertService takes an inserter and the options provided and creates a RetryInsertService.
func (RetryInsertService) InsertRecords ¶
func (ri RetryInsertService) InsertRecords(records ...db.Record) error
InsertRecords uses the inserter to insert the records and tries again if inserting fails. Between each try, it calculates how long to wait and then waits for that period of time before trying again. Only the error from the last failure is returned.
type RetryListGService ¶
type RetryListGService struct {
// contains filtered or unexported fields
}
RetryListGService is a wrapper for a blacklist Updater that attempts to get the blacklist a configurable number of times if the gets fail.
func CreateRetryListGService ¶
func CreateRetryListGService(listGetter blacklist.Updater, options ...Option) RetryListGService
CreateRetryListGService takes an updater and the options provided and creates a RetryListGService.
func (RetryListGService) GetBlacklist ¶
func (ltg RetryListGService) GetBlacklist() (list []blacklist.BlackListedItem, err error)
GetBlacklist uses the updater to get the blacklist and tries again if getting fails. Between each try, it calculates how long to wait and then waits for that period of time before trying again. Only the error from the last failure is returned.
type RetryRGService ¶
type RetryRGService struct {
// contains filtered or unexported fields
}
RetryRGService is a wrapper for a record getter that attempts to get records for a device a configurable number of times if the gets fail.
func CreateRetryRGService ¶
func CreateRetryRGService(recordGetter db.RecordGetter, options ...Option) RetryRGService
CreateRetryRGService takes a record getter and the options provided and creates a RetryRGService.
func (RetryRGService) GetRecords ¶
GetRecords uses the getter to get records for a device and tries again if getting fails. Between each try, it calculates how long to wait and then waits for that period of time before trying again. Only the error from the last failure is returned.
func (RetryRGService) GetRecordsOfType ¶
func (rtg RetryRGService) GetRecordsOfType(deviceID string, limit int, eventType db.EventType) ([]db.Record, error)
GetRecordsOfType uses the getter to get records of a specified type for a device and tries again if getting fails. Between each try, it calculates how long to wait and then waits for that period of time before trying again. Only the error from the last failure is returned.
type RetryUpdateService ¶
type RetryUpdateService struct {
// contains filtered or unexported fields
}
RetryUpdateService is a wrapper for a db.Pruner that attempts either part of the pruning process a configurable number of times.
func CreateRetryUpdateService ¶
func CreateRetryUpdateService(pruner db.Pruner, options ...Option) RetryUpdateService
CreateRetryUpdateService takes a pruner and the options provided and creates a RetryUpdateService.
func (RetryUpdateService) DeleteRecord ¶ added in v0.8.0
func (ru RetryUpdateService) DeleteRecord(shard int, deathdate int64, recordID int64) error
DeleteRecord uses the pruner to delete a record and tries again if deleting fails. Between each try, it calculates how long to wait and then waits for that period of time before trying again. Only the error from the last failure is returned.
func (RetryUpdateService) GetRecordsToDelete ¶ added in v0.8.0
func (ru RetryUpdateService) GetRecordsToDelete(shard int, limit int, deathDate int64) ([]db.RecordToDelete, error)
GetRecordsToDelete uses the pruner to get records and tries again if getting fails. Between each try, it calculates how long to wait and then waits for that period of time before trying again. Only the error from the last failure is returned.