Adjusting arguments and return value of retry function and adding new retry logic to stream

This commit is contained in:
Scott Finlay 2016-11-07 17:10:40 +01:00
parent 092d17a74e
commit a66bce0e4b
2 changed files with 12 additions and 5 deletions

View File

@ -1,8 +1,10 @@
package client
type RetryFunc func(err error) bool
import "context"
type RetryFunc func(ctx context.Context, req Request, retryCount int, err error) (bool, error)
// always retry on error
func alwaysRetry(err error) bool {
return true
func alwaysRetry(ctx context.Context, req Request, retryCount int, err error) (bool, error) {
return true, err
}

View File

@ -300,7 +300,7 @@ func (r *rpcClient) Call(ctx context.Context, request Request, response interfac
return nil
}
if !callOpts.Retry(err) {
if retry, err := callOpts.Retry(ctx, request, i, err); !retry {
return err
}
@ -405,7 +405,12 @@ func (r *rpcClient) Stream(ctx context.Context, request Request, opts ...CallOpt
if rsp.err == nil {
return rsp.stream, nil
}
grr = rsp.err
if retry, err := callOpts.Retry(ctx, request, i, rsp.err); !retry {
return nil, err
}
grr = err
}
}