retryproxy

package
v0.0.0-...-bd56387 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2015 License: MIT Imports: 4 Imported by: 0

README

retryproxy

an etcd retry client which retries against etcd when required

how to use

import "github.com/stensonb/clusterlock/retryproxy"

then, create a retryproxy instead of the etcd keysAPI:

// two options here:
// 1. if you don't want to be notified when the retry proxy needs to retry, pass ec=nil
// 2. if you want to follow when the retry client had to retry, pass an error channel via ec
// NOTE: be sure to read from the error channel (ec), otherwise, you will block the retry
// min uint ; the shortest amount of time to wait (in seconds) on failure
// max uint ; the longest amount of time to wait (in seconds) on failure
c, _ := client.New(cfg)  // a new etcd client
var ec chan error = nil
min := uint(1)
max := uint(60)
ecrp := retryproxy.NewEtcdClientRetryProxy(c, ec, min, max)

// now, use the ecrp just as you would a client.KeysAPI from etcd
// read value from etcd
opts := client.GetOptions{Quorum: true}
resp, err := ecrp.Get(context.Background(), somepath, &opts)

features

  • client.ErrClusterUnavailable errors from ANY call results in an increase in wait time before trying again
  • ANY successful etcd call results in a removal of all wait times for all other etcd calls
  • an optional error channel to monitor each retry
  • support a range minimum and maximum wait times before trying again
  • failed etcd calls roughly double the next call's wait time

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EtcdClientRetryProxy

type EtcdClientRetryProxy struct {
	ErrorChan chan error
	// contains filtered or unexported fields
}

func NewEtcdClientRetryProxy

func NewEtcdClientRetryProxy(c client.Client, ec chan error, min uint, max uint) *EtcdClientRetryProxy

if you don't want to be notified when the retry proxy needs to retry, pass ec=nil

func (*EtcdClientRetryProxy) Create

func (ecrp *EtcdClientRetryProxy) Create(ctx context.Context, key, value string) (*client.Response, error)

func (*EtcdClientRetryProxy) CreateInOrder

func (ecrp *EtcdClientRetryProxy) CreateInOrder(ctx context.Context, dir, value string, opts *client.CreateInOrderOptions) (*client.Response, error)

func (*EtcdClientRetryProxy) Delete

func (*EtcdClientRetryProxy) Get

Satisfy the client.KeysAPI interface

func (*EtcdClientRetryProxy) NewWatcherProxy

func (ecrp *EtcdClientRetryProxy) NewWatcherProxy(key string, opts *client.WatcherOptions) *watcherProxy

func (*EtcdClientRetryProxy) Retry

func (ecrp *EtcdClientRetryProxy) Retry(fn func() (*client.Response, error)) (*client.Response, error)

func (*EtcdClientRetryProxy) Set

func (ecrp *EtcdClientRetryProxy) Set(ctx context.Context, key, value string, opts *client.SetOptions) (*client.Response, error)

func (*EtcdClientRetryProxy) Shutdown

func (ecrp *EtcdClientRetryProxy) Shutdown()

func (*EtcdClientRetryProxy) Update

func (ecrp *EtcdClientRetryProxy) Update(ctx context.Context, key, value string) (*client.Response, error)

func (*EtcdClientRetryProxy) Watcher

func (ecrp *EtcdClientRetryProxy) Watcher(key string, opts *client.WatcherOptions) client.Watcher

Jump to

Keyboard shortcuts

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