forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monit_retry_client.go
50 lines (43 loc) · 1.18 KB
/
monit_retry_client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package monit
import (
"net/http"
"time"
"code.cloudfoundry.org/clock"
"github.com/cloudfoundry/bosh-utils/httpclient"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
)
type monitRetryClient struct {
delegate HTTPClient
maxUnavailableAttempts uint
maxOtherAttempts uint
retryDelay time.Duration
logger boshlog.Logger
}
func NewMonitRetryClient(
delegate HTTPClient,
maxUnavailableAttempts uint,
maxOtherAttempts uint,
retryDelay time.Duration,
logger boshlog.Logger,
) httpclient.Client {
return &monitRetryClient{
delegate: delegate,
maxUnavailableAttempts: maxUnavailableAttempts,
maxOtherAttempts: maxOtherAttempts,
retryDelay: retryDelay,
logger: logger,
}
}
func (r *monitRetryClient) Do(req *http.Request) (*http.Response, error) {
requestRetryable := httpclient.NewRequestRetryable(req, r.delegate, r.logger, nil)
timeService := clock.NewClock()
retryStrategy := NewMonitRetryStrategy(
requestRetryable,
r.maxUnavailableAttempts,
r.maxOtherAttempts,
r.retryDelay,
timeService,
)
err := retryStrategy.Try()
return requestRetryable.Response(), err
}