/
retry_core.go
57 lines (45 loc) · 1.49 KB
/
retry_core.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
51
52
53
54
55
56
57
package gocb
import "github.com/couchbase/gocbcore/v10"
func translateCoreRetryReasons(reasons []gocbcore.RetryReason) []RetryReason {
var reasonsOut []RetryReason
for _, retryReason := range reasons {
gocbReason, ok := retryReason.(RetryReason)
if !ok {
logErrorf("Failed to assert gocbcore retry reason to gocb retry reason: %v", retryReason)
continue
}
reasonsOut = append(reasonsOut, gocbReason)
}
return reasonsOut
}
type wrappedCoreRetryRequest struct {
req gocbcore.RetryRequest
}
func (req *wrappedCoreRetryRequest) RetryAttempts() uint32 {
return req.req.RetryAttempts()
}
func (req *wrappedCoreRetryRequest) Identifier() string {
return req.req.Identifier()
}
func (req *wrappedCoreRetryRequest) Idempotent() bool {
return req.req.Idempotent()
}
func (req *wrappedCoreRetryRequest) RetryReasons() []RetryReason {
return translateCoreRetryReasons(req.req.RetryReasons())
}
func newCoreRetryStrategyWrapper(strategy RetryStrategy) *coreRetryStrategyWrapper {
return &coreRetryStrategyWrapper{
wrapped: strategy,
}
}
type coreRetryStrategyWrapper struct {
wrapped RetryStrategy
}
// RetryAfter calculates and returns a RetryAction describing how long to wait before retrying an operation.
func (rs *coreRetryStrategyWrapper) RetryAfter(req gocbcore.RetryRequest, reason gocbcore.RetryReason) gocbcore.RetryAction {
wreq := &wrappedCoreRetryRequest{
req: req,
}
wrappedAction := rs.wrapped.RetryAfter(wreq, RetryReason(reason))
return gocbcore.RetryAction(wrappedAction)
}