diff --git a/hystrix/hystrix_client.go b/hystrix/hystrix_client.go index 563aa7c..ae04066 100644 --- a/hystrix/hystrix_client.go +++ b/hystrix/hystrix_client.go @@ -2,6 +2,7 @@ package hystrix import ( "bytes" + "context" "io" "io/ioutil" "net/http" @@ -15,7 +16,7 @@ import ( "github.com/pkg/errors" ) -type fallbackFunc func(error) error +type fallbackFunc func(context.Context, error) error // Client is the hystrix client implementation type Client struct { @@ -30,7 +31,7 @@ type Client struct { errorPercentThreshold int retryCount int retrier heimdall.Retriable - fallbackFunc func(err error) error + fallbackFunc func(ctx context.Context, err error) error statsD *plugins.StatsdCollectorConfig } @@ -186,7 +187,7 @@ func (hhc *Client) Do(request *http.Request) (*http.Response, error) { response.Body.Close() } - err = hystrix.Do(hhc.hystrixCommandName, func() error { + err = hystrix.DoC(request.Context(), hhc.hystrixCommandName, func(ctx context.Context) error { response, err = hhc.client.Do(request) if bodyReader != nil { // Reset the body reader after the request since at this point it's already read diff --git a/hystrix/hystrix_client_test.go b/hystrix/hystrix_client_test.go index b90d084..f8c11dd 100644 --- a/hystrix/hystrix_client_test.go +++ b/hystrix/hystrix_client_test.go @@ -2,6 +2,7 @@ package hystrix import ( "bytes" + "context" "io/ioutil" "net/http" "net/http/httptest" @@ -430,7 +431,7 @@ func TestHystrixHTTPClientReturnsFallbackFailureWithAFallBackFunctionWhichReturn WithErrorPercentThreshold(10), WithSleepWindow(100), WithRequestVolumeThreshold(10), - WithFallbackFunc(func(err error) error { + WithFallbackFunc(func(ctx context.Context, err error) error { // do something in the fallback function return err }), @@ -453,7 +454,7 @@ func TestFallBackFunctionIsCalledWithHystrixHTTPClient(t *testing.T) { WithErrorPercentThreshold(10), WithSleepWindow(100), WithRequestVolumeThreshold(10), - WithFallbackFunc(func(err error) error { + WithFallbackFunc(func(ctx context.Context, err error) error { called = true return err }), @@ -474,7 +475,7 @@ func TestHystrixHTTPClientReturnsFallbackFailureWithAFallBackFunctionWhichReturn WithErrorPercentThreshold(10), WithSleepWindow(100), WithRequestVolumeThreshold(10), - WithFallbackFunc(func(err error) error { + WithFallbackFunc(func(ctx context.Context, err error) error { // do something in the fallback function return nil }),