Documentation ¶
Index ¶
- type Client
- func (d *Client) Close() (err error)
- func (d *Client) CloseConnection(c serverutil.Client) (err error)
- func (d *Client) Connection(ctx context.Context) (serverutil.Client, error)
- func (d *Client) Disconnect(when time.Duration)
- func (d *Client) LocalAddr() net.Addr
- func (d *Client) Log() log.Interface
- func (d *Client) RemoteAddr() net.Addr
- func (d *Client) Retry(ctx context.Context, f RetryFunc) error
- func (d *Client) SetLogger(l log.Interface)
- func (d *Client) SetUserErrorFunc(f UserErrorFunc)
- func (d *Client) TaskCodes() (tc []serverutil.TaskCode)
- func (d *Client) Timestamp() time.Time
- type ConnectionFunc
- type RetryFunc
- type UserErrorFunc
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 ¶
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 ¶
Connection returns a connection to the server. This will establish a new connection if necessary.
func (*Client) Disconnect ¶
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) RemoteAddr ¶
RemoteAddr returns the remote network address.
func (*Client) Retry ¶
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) 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.
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 ¶
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.