Skip to content

Commit

Permalink
feat: add retry to refresh token
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyu committed Jun 5, 2024
1 parent 79af304 commit e824527
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
8 changes: 6 additions & 2 deletions pkg/controller/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var (

func getAccountFromSettings(admin string) (userid, token string, err error) {
settingsUrl := fmt.Sprintf("http://settings-service.user-space-%s/api/account", admin)
client := resty.New().SetTimeout(2 * time.Second)
client := resty.New().SetTimeout(2 * time.Second).SetRetryCount(3)

req := &ProxyRequest{
Op: "getAccount",
Expand Down Expand Up @@ -158,7 +158,11 @@ func GetAwsAccountFromCloud(ctx context.Context, client dynamic.Interface, bucke
return nil, err
}

httpClient := resty.New().SetTimeout(15 * time.Second).SetDebug(true)
httpClient := resty.New().SetTimeout(15 * time.Second).
SetDebug(true).
SetRetryCount(5).
SetRetryWaitTime(30 * time.Second).
SetRetryMaxWaitTime(180 * time.Second)
duration := 12 * time.Hour
resp, err := httpClient.R().
SetFormData(map[string]string{
Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controllers

import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -42,7 +43,8 @@ func NewNodeInitController(c client.Client, schema *runtime.Scheme, config *rest
nic := &NodeInitController{Client: c, scheme: schema, cron: cron.New()}
schedule := os.Getenv("SCHEDULE")
if schedule == "" {
schedule = "0 */8 * * *"
// random timer schedule, to avoid too much concurrent api requets
schedule = fmt.Sprintf("%d */8 * * *", time.Now().Minute())
}

if isMaster, _, err := nic.isMasterNode(config); err != nil {
Expand Down
11 changes: 11 additions & 0 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package controllers

import (
"testing"
)

func TestRand(t *testing.T) {

println("schedule")

}

0 comments on commit e824527

Please sign in to comment.