Skip to content

Commit

Permalink
increase backoff (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-cronus authored Oct 29, 2024
1 parent 61c21e1 commit 3858d4c
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 20 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.5-0.20231225225746-43d5d4cd4e0e // indirect
github.com/google/pprof v0.0.0-20241023014458-598669927662 // indirect
github.com/google/pprof v0.0.0-20241029010322-833c56d90c8e // indirect
github.com/google/s2a-go v0.1.8 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
Expand Down Expand Up @@ -189,7 +189,7 @@ require (
google.golang.org/genproto/googleapis/api v0.0.0-20241021214115-324edc3d5d38 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/grpc/stats/opentelemetry v0.0.0-20241025232817-cb329375b14e // indirect
google.golang.org/grpc/stats/opentelemetry v0.0.0-20241028142157-ada6787961b3 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian/v3 v3.3.3 h1:DIhPTQrbPkgs2yJYdXU/eNACCG5DVQjySNRNlflZ9Fc=
github.com/google/martian/v3 v3.3.3/go.mod h1:iEPrYcgCF7jA9OtScMFQyAlZZ4YXTKEtJ1E6RWzmBA0=
github.com/google/pprof v0.0.0-20241023014458-598669927662 h1:SKMkD83p7FwUqKmBsPdLHF5dNyxq3jOWwu9w9UyH5vA=
github.com/google/pprof v0.0.0-20241023014458-598669927662/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
github.com/google/pprof v0.0.0-20241029010322-833c56d90c8e h1:v7R0PZoC2p1KWQmv1+GqCXQe59Ab1TkDF8Y9Lg2W6m4=
github.com/google/pprof v0.0.0-20241029010322-833c56d90c8e/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
github.com/google/s2a-go v0.1.8 h1:zZDs9gcbt9ZPLV0ndSyQk6Kacx2g/X+SKYovpnz3SMM=
github.com/google/s2a-go v0.1.8/go.mod h1:6iNWHTpQ+nfNRN5E00MSdfDwVesa8hhS32PhPO8deJA=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand Down Expand Up @@ -579,8 +579,8 @@ google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
google.golang.org/grpc/stats/opentelemetry v0.0.0-20241025232817-cb329375b14e h1:SoMI+r+Qsp379U9BlVzrHtqAqYP3NEv9vNhYqUaAWOg=
google.golang.org/grpc/stats/opentelemetry v0.0.0-20241025232817-cb329375b14e/go.mod h1:jzYlkSMbKypzuu6xoAEijsNVo9ZeDF1u/zCfFgsx7jg=
google.golang.org/grpc/stats/opentelemetry v0.0.0-20241028142157-ada6787961b3 h1:hUfOButuEtpc0UvYiaYRbNwxVYr0mQQOWq6X8beJ9Gc=
google.golang.org/grpc/stats/opentelemetry v0.0.0-20241028142157-ada6787961b3/go.mod h1:jzYlkSMbKypzuu6xoAEijsNVo9ZeDF1u/zCfFgsx7jg=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
32 changes: 26 additions & 6 deletions kyc/face/internal/threedivi/threedivi.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,17 @@ func (t *threeDivi) updateAvailability(ctx context.Context) error {
}
if resp, err := req.
SetContext(ctx).
SetRetryCount(10). //nolint:gomnd // .
SetRetryBackoffInterval(10*stdlibtime.Millisecond, 1*stdlibtime.Second). //nolint:gomnd // .
SetRetryCount(10). //nolint:gomnd // .
SetRetryInterval(func(_ *req.Response, attempt int) stdlibtime.Duration {
switch {
case attempt <= 1:
return 100 * stdlibtime.Millisecond //nolint:gomnd // .
case attempt == 2: //nolint:gomnd // .
return 1 * stdlibtime.Second
default:
return 10 * stdlibtime.Second //nolint:gomnd // .
}
}).
SetRetryHook(func(resp *req.Response, err error) {
if err != nil {
log.Error(errors.Wrap(err, "failed to check availability of face auth, retrying... "))
Expand Down Expand Up @@ -199,8 +208,8 @@ func (t *threeDivi) Reset(ctx context.Context, user *users.User, fetchState bool
var resp *req.Response
if resp, err = req.
SetContext(ctx).
SetRetryCount(10). //nolint:gomnd // .
SetRetryBackoffInterval(10*stdlibtime.Millisecond, 1*stdlibtime.Second). //nolint:gomnd // .
SetRetryCount(10). //nolint:gomnd // .
SetRetryInterval(backoff).
SetRetryHook(func(resp *req.Response, err error) {
if err != nil {
log.Error(errors.Wrap(err, "failed to delete face auth state for user, retrying... "))
Expand Down Expand Up @@ -293,13 +302,24 @@ func stepIdx(step users.KYCStep) int {
return int(step) - 1
}

func backoff(_ *req.Response, attempt int) stdlibtime.Duration {
switch {
case attempt <= 1:
return 100 * stdlibtime.Millisecond //nolint:gomnd // .
case attempt == 2: //nolint:gomnd // .
return 1 * stdlibtime.Second
default:
return 10 * stdlibtime.Second //nolint:gomnd // .
}
}

func (t *threeDivi) searchIn3DiviForApplicant(ctx context.Context, userID users.UserID) (*applicant, error) {
getApplicantURL := fmt.Sprintf("%v/publicapi/api/v2/private/Applicants/ByReferenceId/%v", t.cfg.ThreeDiVi.BAFHost, userID)
log.Debug("GET ", getApplicantURL)
if resp, err := req.
SetContext(ctx).
SetRetryCount(10). //nolint:gomnd // .
SetRetryBackoffInterval(10*stdlibtime.Millisecond, 1*stdlibtime.Second). //nolint:gomnd // .
SetRetryCount(10). //nolint:gomnd // .
SetRetryInterval(backoff).
SetRetryHook(func(resp *req.Response, err error) {
if err != nil {
log.Error(errors.Wrap(err, "failed to match applicantId for user, retrying... "))
Expand Down
11 changes: 10 additions & 1 deletion kyc/face/remote_kyc_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@ func (c *client) syncKYCConfigJSON(ctx context.Context) error {
if resp, err := req.
SetContext(ctx).
SetRetryCount(25).
SetRetryBackoffInterval(10*stdlibtime.Millisecond, 1*stdlibtime.Second).
SetRetryInterval(func(_ *req.Response, attempt int) stdlibtime.Duration {
switch {
case attempt <= 1:
return 100 * stdlibtime.Millisecond //nolint:gomnd // .
case attempt == 2: //nolint:gomnd // .
return 1 * stdlibtime.Second
default:
return 10 * stdlibtime.Second //nolint:gomnd // .
}
}).
SetRetryHook(func(resp *req.Response, err error) {
if err != nil {
log.Error(errors.Wrap(err, "failed to fetch KYCConfigJSON, retrying...")) //nolint:revive // .
Expand Down
13 changes: 11 additions & 2 deletions kyc/linking/linking.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,17 @@ func (l *linker) fetchTokenData(ctx context.Context, tenant, token string) (*use
}
if resp, err = req.
SetContext(ctx).
SetRetryCount(10). //nolint:gomnd // .
SetRetryBackoffInterval(10*stdlibtime.Millisecond, 1*stdlibtime.Second). //nolint:gomnd // .
SetRetryCount(10). //nolint:gomnd // .
SetRetryInterval(func(_ *req.Response, attempt int) stdlibtime.Duration {
switch {
case attempt <= 1:
return 100 * stdlibtime.Millisecond //nolint:gomnd // .
case attempt == 2: //nolint:gomnd // .
return 1 * stdlibtime.Second
default:
return 10 * stdlibtime.Second //nolint:gomnd // .
}
}).
SetRetryHook(func(resp *req.Response, err error) {
if err != nil {
log.Error(errors.Wrap(err, "failed to check accounts linking, retrying... "))
Expand Down
11 changes: 10 additions & 1 deletion kyc/quiz/remote_kyc_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@ func (r *repositoryImpl) syncKYCConfigJSON(ctx context.Context) error {
if resp, err := req.
SetContext(ctx).
SetRetryCount(25).
SetRetryBackoffInterval(10*stdlibtime.Millisecond, 1*stdlibtime.Second).
SetRetryInterval(func(_ *req.Response, attempt int) stdlibtime.Duration {
switch {
case attempt <= 1:
return 100 * stdlibtime.Millisecond //nolint:gomnd // .
case attempt == 2: //nolint:gomnd // .
return 1 * stdlibtime.Second
default:
return 10 * stdlibtime.Second //nolint:gomnd // .
}
}).
SetRetryHook(func(resp *req.Response, err error) {
if err != nil {
log.Error(errors.Wrap(err, "failed to fetch KYCConfigJSON, retrying...")) //nolint:revive // .
Expand Down
22 changes: 20 additions & 2 deletions kyc/social/remote_kyc_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@ func (r *repository) syncKYCConfigJSON1(ctx context.Context) error {
if resp, err := req.
SetContext(ctx).
SetRetryCount(25).
SetRetryBackoffInterval(10*stdlibtime.Millisecond, 1*stdlibtime.Second).
SetRetryInterval(func(_ *req.Response, attempt int) stdlibtime.Duration {
switch {
case attempt <= 1:
return 100 * stdlibtime.Millisecond //nolint:gomnd // .
case attempt == 2: //nolint:gomnd // .
return 1 * stdlibtime.Second
default:
return 10 * stdlibtime.Second //nolint:gomnd // .
}
}).
SetRetryHook(func(resp *req.Response, err error) {
if err != nil {
log.Error(errors.Wrap(err, "failed to fetch KYCConfigJSON, retrying...")) //nolint:revive // .
Expand Down Expand Up @@ -94,7 +103,16 @@ func (r *repository) syncKYCConfigJSON2(ctx context.Context) error {
if resp, err := req.
SetContext(ctx).
SetRetryCount(25).
SetRetryBackoffInterval(10*stdlibtime.Millisecond, 1*stdlibtime.Second).
SetRetryInterval(func(_ *req.Response, attempt int) stdlibtime.Duration {
switch {
case attempt <= 1:
return 100 * stdlibtime.Millisecond //nolint:gomnd // .
case attempt == 2: //nolint:gomnd // .
return 1 * stdlibtime.Second
default:
return 10 * stdlibtime.Second //nolint:gomnd // .
}
}).
SetRetryHook(func(resp *req.Response, err error) {
if err != nil {
log.Error(errors.Wrap(err, "failed to fetch KYCConfigJSON, retrying...")) //nolint:revive // .
Expand Down
13 changes: 11 additions & 2 deletions users/user_growth.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,17 @@ func (r *repository) GetUserGrowth(ctx context.Context, days uint64, tz *stdlibt
func (r *repository) getAdoptionTotalActiveUsersValue(ctx context.Context) (totalActiveUsers uint64, err error) {
resp, err := req.
SetContext(ctx).
SetRetryCount(25). //nolint:gomnd,mnd // .
SetRetryBackoffInterval(10*stdlibtime.Millisecond, 1*stdlibtime.Second). //nolint:gomnd,mnd // .
SetRetryCount(25). //nolint:gomnd,mnd // .
SetRetryInterval(func(_ *req.Response, attempt int) stdlibtime.Duration {
switch {
case attempt <= 1:
return 100 * stdlibtime.Millisecond //nolint:gomnd // .
case attempt == 2: //nolint:gomnd // .
return 1 * stdlibtime.Second
default:
return 10 * stdlibtime.Second //nolint:gomnd // .
}
}).
SetRetryHook(func(resp *req.Response, err error) {
if err != nil {
log.Error(errors.Wrap(err, "failed to fetch adoption, retrying...")) //nolint:revive // .
Expand Down

0 comments on commit 3858d4c

Please sign in to comment.