-
Notifications
You must be signed in to change notification settings - Fork 115
/
monit_retry_client.go
50 lines (43 loc) · 1.19 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"
boshhttp "github.com/cloudfoundry/bosh-utils/http"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
"github.com/pivotal-golang/clock"
)
type monitRetryClient struct {
delegate boshhttp.Client
maxUnavailableAttempts uint
maxOtherAttempts uint
retryDelay time.Duration
logger boshlog.Logger
}
func NewMonitRetryClient(
delegate boshhttp.Client,
maxUnavailableAttempts uint,
maxOtherAttempts uint,
retryDelay time.Duration,
logger boshlog.Logger,
) boshhttp.Client {
return &monitRetryClient{
delegate: delegate,
maxUnavailableAttempts: maxUnavailableAttempts,
maxOtherAttempts: maxOtherAttempts,
retryDelay: retryDelay,
logger: logger,
}
}
func (r *monitRetryClient) Do(req *http.Request) (*http.Response, error) {
requestRetryable := boshhttp.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
}