mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-05-17 20:29:03 +08:00
feat(home): reduce reconnect interval for control center to 1 second
- Introduced `homeReconnectInterval` constant to simplify retry configuration. - Replaced hardcoded 30-second retries with the new 1-second interval for improved responsiveness.
This commit is contained in:
@@ -20,6 +20,8 @@ const (
|
||||
redisChannelConfig = "config"
|
||||
redisKeyModels = "models"
|
||||
redisKeyUsage = "usage"
|
||||
|
||||
homeReconnectInterval = time.Second
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -290,44 +292,44 @@ func (c *Client) StartConfigSubscriber(ctx context.Context, onConfig func([]byte
|
||||
c.Close()
|
||||
|
||||
if errEnsure := c.ensureClients(); errEnsure != nil {
|
||||
log.Warn("unable to connect to home control center, retrying in 30 seconds")
|
||||
sleepWithContext(ctx, 30*time.Second)
|
||||
log.Warn("unable to connect to home control center, retrying in 1 second")
|
||||
sleepWithContext(ctx, homeReconnectInterval)
|
||||
continue
|
||||
}
|
||||
|
||||
if errPing := c.Ping(ctx); errPing != nil {
|
||||
log.Warn("unable to connect to home control center, retrying in 30 seconds")
|
||||
sleepWithContext(ctx, 30*time.Second)
|
||||
log.Warn("unable to connect to home control center, retrying in 1 second")
|
||||
sleepWithContext(ctx, homeReconnectInterval)
|
||||
continue
|
||||
}
|
||||
|
||||
raw, errGet := c.GetConfig(ctx)
|
||||
if errGet != nil {
|
||||
log.Warn("unable to fetch config from home control center, retrying in 30 seconds")
|
||||
sleepWithContext(ctx, 30*time.Second)
|
||||
log.Warn("unable to fetch config from home control center, retrying in 1 second")
|
||||
sleepWithContext(ctx, homeReconnectInterval)
|
||||
continue
|
||||
}
|
||||
if errApply := onConfig(raw); errApply != nil {
|
||||
log.Warn("unable to apply config from home control center, retrying in 30 seconds")
|
||||
sleepWithContext(ctx, 30*time.Second)
|
||||
log.Warn("unable to apply config from home control center, retrying in 1 second")
|
||||
sleepWithContext(ctx, homeReconnectInterval)
|
||||
continue
|
||||
}
|
||||
|
||||
if c.sub == nil {
|
||||
sleepWithContext(ctx, 30*time.Second)
|
||||
sleepWithContext(ctx, homeReconnectInterval)
|
||||
continue
|
||||
}
|
||||
|
||||
pubsub := c.sub.Subscribe(ctx, redisChannelConfig)
|
||||
if pubsub == nil {
|
||||
sleepWithContext(ctx, 30*time.Second)
|
||||
sleepWithContext(ctx, homeReconnectInterval)
|
||||
continue
|
||||
}
|
||||
|
||||
// Ensure the subscription is established before marking heartbeat OK.
|
||||
if _, errReceive := pubsub.Receive(ctx); errReceive != nil {
|
||||
_ = pubsub.Close()
|
||||
sleepWithContext(ctx, 30*time.Second)
|
||||
sleepWithContext(ctx, homeReconnectInterval)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -338,6 +340,7 @@ func (c *Client) StartConfigSubscriber(ctx context.Context, onConfig func([]byte
|
||||
if errMsg != nil {
|
||||
_ = pubsub.Close()
|
||||
c.heartbeatOK.Store(false)
|
||||
sleepWithContext(ctx, homeReconnectInterval)
|
||||
break
|
||||
}
|
||||
if msg == nil {
|
||||
|
||||
Reference in New Issue
Block a user