Skip to content

Commit

Permalink
add sync server list timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
zouyx committed Apr 10, 2021
1 parent 26269e4 commit fd81f9b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions component/serverlist/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package serverlist
import (
"encoding/json"
"github.com/zouyx/agollo/v4/env/server"
"strconv"
"time"

"github.com/zouyx/agollo/v4/component"
Expand Down Expand Up @@ -74,10 +75,18 @@ func SyncServerIPList(appConfigFunc func() config.AppConfig) (map[string]*config
}

appConfig := appConfigFunc()
serverMap, err := http.Request(appConfig.GetServicesConfigURL(), &env.ConnectConfig{
c := &env.ConnectConfig{
AppID: appConfig.AppID,
Secret: appConfig.Secret,
}, &http.CallBack{
}
if appConfigFunc().SyncServerTimeout > 0 {
duration, err := time.ParseDuration(strconv.Itoa(appConfigFunc().SyncServerTimeout) + "s")
if err != nil {
return nil, err
}
c.Timeout = duration
}
serverMap, err := http.Request(appConfig.GetServicesConfigURL(), c, &http.CallBack{
SuccessCallBack: SyncServerIPListSuccessCallBack,
AppConfigFunc: appConfigFunc,
})
Expand Down
1 change: 1 addition & 0 deletions component/serverlist/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func getTestAppConfig() *config.AppConfig {
"cluster": "dev",
"namespaceName": "application",
"ip": "localhost:8888",
"syncServerTimeout":2,
"releaseKey": "1"
}`
c, _ := env.Unmarshal([]byte(jsonStr))
Expand Down
1 change: 1 addition & 0 deletions env/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type AppConfig struct {
IsBackupConfig bool `default:"true" json:"isBackupConfig"`
BackupConfigPath string `json:"backupConfigPath"`
Secret string `json:"secret"`
SyncServerTimeout int `json:"syncServerTimeout"`
notificationsMap *notificationsMap
currentConnApolloConfig *CurrentApolloConfig
}
Expand Down

0 comments on commit fd81f9b

Please sign in to comment.