Adjusting names

This commit is contained in:
Scott Finlay 2016-11-07 09:40:11 +01:00
parent d7e4062a0e
commit 092d17a74e
5 changed files with 16 additions and 30 deletions

View File

@ -68,8 +68,8 @@ var (
DefaultClient Client = newRpcClient()
// DefaultBackoff is the default backoff function for retries
DefaultBackoff = exponentialBackoff
// DefaultCheckIfRetriable is the default check-for-retry function for retries
DefaultCheckIfRetriable = AlwaysRetry
// DefaultRetry is the default check-for-retry function for retries
DefaultRetry = alwaysRetry
// DefaultRetries is the default number of times a request is tried
DefaultRetries = 1
// DefaultRequestTimeout is the default request timeout

View File

@ -1,22 +0,0 @@
package client
import (
"github.com/micro/go-micro/errors"
)
type IsRetriableFunc func(err error) bool
// always retry on error
func AlwaysRetry(err error) bool {
return true
}
func Only500Errors(err error) bool {
errorData := errors.Parse(err.Error())
if(errorData.Code >= 500) {
return true
}
return false
}

View File

@ -44,7 +44,7 @@ type CallOptions struct {
// Backoff func
Backoff BackoffFunc
// Check if retriable func
CheckIfRetriable IsRetriableFunc
Retry RetryFunc
// Transport Dial Timeout
DialTimeout time.Duration
// Number of Call attempts
@ -76,7 +76,7 @@ func newOptions(options ...Option) Options {
Codecs: make(map[string]codec.NewCodec),
CallOptions: CallOptions{
Backoff: DefaultBackoff,
CheckIfRetriable: DefaultCheckIfRetriable,
Retry: DefaultRetry,
Retries: DefaultRetries,
RequestTimeout: DefaultRequestTimeout,
DialTimeout: transport.DefaultDialTimeout,
@ -224,11 +224,11 @@ func WithBackoff(fn BackoffFunc) CallOption {
}
}
// WithCheckIfRetriable is a CallOption which overrides that which
// WithRetry is a CallOption which overrides that which
// set in Options.CallOptions
func WithCheckIfRetriable(fn IsRetriableFunc) CallOption {
func WithRetry(fn RetryFunc) CallOption {
return func(o *CallOptions) {
o.CheckIfRetriable = fn
o.Retry = fn
}
}

8
client/retry.go Normal file
View File

@ -0,0 +1,8 @@
package client
type RetryFunc func(err error) bool
// always retry on error
func alwaysRetry(err error) bool {
return true
}

View File

@ -300,7 +300,7 @@ func (r *rpcClient) Call(ctx context.Context, request Request, response interfac
return nil
}
if !callOpts.CheckIfRetriable(err) {
if !callOpts.Retry(err) {
return err
}