File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 44 "errors"
55 "net"
66 "net/http"
7+ "time"
78
89 resty "github.com/go-resty/resty/v2"
910 "github.com/shellhub-io/shellhub/pkg/worker"
@@ -23,6 +24,10 @@ type Client interface {
2324type Config struct {
2425 // RetryCount defines how many times the client should retry a request in case of failure.
2526 RetryCount int
27+ // RetryWaitTime defines the wait time between retries.
28+ RetryWaitTime time.Duration
29+ // RetryMaxWaitTime defines the maximum wait time between retries.
30+ RetryMaxWaitTime time.Duration
2631}
2732
2833type client struct {
@@ -50,7 +55,10 @@ func NewClient(opts ...clientOption) (Client, error) {
5055 c := & client {
5156 http : httpClient ,
5257 Config : & Config {
53- RetryCount : 3 ,
58+ // NOTE: Default values can be overridden using the WithConfig option.
59+ RetryCount : 3 ,
60+ RetryWaitTime : 5 * time .Second ,
61+ RetryMaxWaitTime : 20 * time .Second ,
5462 },
5563 }
5664
@@ -66,6 +74,8 @@ func NewClient(opts ...clientOption) (Client, error) {
6674
6775 httpClient .SetBaseURL ("http://api:8080" )
6876 httpClient .SetRetryCount (c .Config .RetryCount )
77+ httpClient .SetRetryWaitTime (c .Config .RetryWaitTime )
78+ httpClient .SetRetryMaxWaitTime (c .Config .RetryMaxWaitTime )
6979 httpClient .AddRetryCondition (func (r * resty.Response , err error ) bool {
7080 if _ , ok := err .(net.Error ); ok { // if the error is a network error, retry.
7181 return true
You can’t perform that action at this time.
0 commit comments