fix: fix scripts functions upload

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>
pull/1721/head
Xinwei Xiong (cubxxw) 2 years ago
parent 97baaacaa7
commit 116c9b37cb

@ -43,12 +43,10 @@ const (
// defaultCfgPath is the default path of the configuration file.
defaultCfgPath = "../../../../../config/config.yaml"
minioHealthCheckDuration = 1
maxRetry = 10
maxRetry = 100
componentStartErrCode = 6000
configErrCode = 6001
mongoConnTimeout = 10 * time.Second
redisConnTimeout = 5 * time.Second // Connection timeout for Redis
mongoConnTimeout = 30 * time.Second
)
const (
@ -252,8 +250,9 @@ func checkMinio() (string, error) {
return str, nil
}
// checkRedis checks the Redis connection with retries and timeout
// checkRedis checks the Redis connection
func checkRedis() (string, error) {
// Prioritize environment variables
address := getEnv("REDIS_ADDRESS", strings.Join(config.Config.Redis.Address, ","))
username := getEnv("REDIS_USERNAME", config.Config.Redis.Username)
password := getEnv("REDIS_PASSWORD", config.Config.Redis.Password)
@ -262,9 +261,6 @@ func checkRedis() (string, error) {
redisAddresses := strings.Split(address, ",")
var redisClient redis.UniversalClient
var err error
for attempt := 0; attempt <= maxRetry; attempt++ {
if len(redisAddresses) > 1 {
// Use cluster client for multiple addresses
redisClient = redis.NewClusterClient(&redis.ClusterOptions{
@ -280,26 +276,15 @@ func checkRedis() (string, error) {
Password: password,
})
}
ctx, cancel := context.WithTimeout(context.Background(), redisConnTimeout)
defer cancel()
defer redisClient.Close()
// Ping Redis to check connectivity
_, err = redisClient.Ping(ctx).Result()
if err == nil {
break
}
if attempt < maxRetry {
fmt.Printf("Failed to connect to Redis, retrying: %s\n", err)
time.Sleep(time.Second * time.Duration(attempt+1)) // Exponential backoff
}
}
_, err := redisClient.Ping(context.Background()).Result()
str := "the addr is:" + strings.Join(redisAddresses, ",")
if err != nil {
return "", err // Wrap or handle the error as needed
return "", errs.Wrap(errStr(err, str))
}
defer redisClient.Close()
str := "The addr is: " + strings.Join(redisAddresses, ",")
return str, nil
}

Loading…
Cancel
Save