From 092d17a74e741b6b780364430ffbfff32387ff26 Mon Sep 17 00:00:00 2001 From: Scott Finlay Date: Mon, 7 Nov 2016 09:40:11 +0100 Subject: [PATCH] Adjusting names --- client/client.go | 4 ++-- client/is_retriable.go | 22 ---------------------- client/options.go | 10 +++++----- client/retry.go | 8 ++++++++ client/rpc_client.go | 2 +- 5 files changed, 16 insertions(+), 30 deletions(-) delete mode 100644 client/is_retriable.go create mode 100644 client/retry.go diff --git a/client/client.go b/client/client.go index 5e8fe23d..e7a8536d 100644 --- a/client/client.go +++ b/client/client.go @@ -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 diff --git a/client/is_retriable.go b/client/is_retriable.go deleted file mode 100644 index 01fc8c47..00000000 --- a/client/is_retriable.go +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/client/options.go b/client/options.go index b5104990..da89c237 100644 --- a/client/options.go +++ b/client/options.go @@ -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 } } diff --git a/client/retry.go b/client/retry.go new file mode 100644 index 00000000..df74abec --- /dev/null +++ b/client/retry.go @@ -0,0 +1,8 @@ +package client + +type RetryFunc func(err error) bool + +// always retry on error +func alwaysRetry(err error) bool { + return true +} diff --git a/client/rpc_client.go b/client/rpc_client.go index b621eae2..0ad84805 100644 --- a/client/rpc_client.go +++ b/client/rpc_client.go @@ -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 }