dialer

package
v0.0.0-...-7847555 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2018 License: CC0-1.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client provides a way to automatically redial a connection to a server and retry tasks on loss of connection.

func New

func New(f ConnectionFunc) (*Client, error)

New returns a new dialer using the given connection function.

func (*Client) Close

func (d *Client) Close() (err error)

Close closes the connection to the server, and prevents any new connections from being established.

func (*Client) CloseConnection

func (d *Client) CloseConnection(c serverutil.Client) (err error)

CloseConnection closes the connection to the server, but allows a new connection to be established if necessary.

func (*Client) Connection

func (d *Client) Connection(ctx context.Context) (serverutil.Client, error)

Connection returns a connection to the server. This will establish a new connection if necessary.

func (*Client) Disconnect

func (d *Client) Disconnect(when time.Duration)

Disconnect begins a graceful disconnection, preventing new tasks from running, and scheduling a future Close on the connection after given duration has elapsed. Note that there is no way to cancel a graceful disconnection once started. If Disconnect is called again, then the final Close will be performed after the shortest of the two durations has expired. This is a non-blocking method.

func (*Client) LocalAddr

func (d *Client) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*Client) Log

func (d *Client) Log() log.Interface

Log returns the logger.

func (*Client) RemoteAddr

func (d *Client) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

func (*Client) Retry

func (d *Client) Retry(ctx context.Context, f RetryFunc) error

Retry attempts to call the retry function f. On failure, it will be retried with exponential back-off. The exponential back-off caps out at approximately 16 seconds. This will try netutil.MaxDialAttempts times before abandoning the attempt; you can use the context to cancel the attempt sooner.

func (*Client) SetLogger

func (d *Client) SetLogger(l log.Interface)

SetLogger sets a logger.

func (*Client) SetUserErrorFunc

func (d *Client) SetUserErrorFunc(f UserErrorFunc)

SetUserErrorFunc sets the given user error function.

func (*Client) TaskCodes

func (d *Client) TaskCodes() (tc []serverutil.TaskCode)

TaskCodes returns a slice of all assigned tasks codes. When relevant, the task codes are sorted in assigned order, from oldest (at index 0) to most recent.

func (*Client) Timestamp

func (d *Client) Timestamp() time.Time

Timestamp returns the connection timestamp for the client.

type ConnectionFunc

type ConnectionFunc func(context.Context) (serverutil.Client, error)

ConnectionFunc is a function that can be called to establish a client connection to a server.

type RetryFunc

type RetryFunc func(context.Context, serverutil.Client) error

RetryFunc is a function that can be safely called multiple times on failure.

type UserErrorFunc

type UserErrorFunc func(error) bool

UserErrorFunc is a function that can be called to determine whether the given error is transient (in which case the connection should be re-established and the task retried) or caused by the user. A return value of true means that the error was caused by the user and the task should not be retried. Errors of type context.Canceled, context.DeadlineExceeded, and serverutil.ErrorCoder are always determined to be user errors and will not be passed to the user error function.

Jump to

Keyboard shortcuts

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