🐛 fix: Fixed the slave service unsynchronized data (#191)
This commit is contained in:
parent
f26a7839c9
commit
6ab116c0eb
@ -146,15 +146,15 @@ func UpdateAllChannelsBalance(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func AutomaticallyUpdateChannels(frequency int) {
|
||||
if frequency <= 0 {
|
||||
return
|
||||
}
|
||||
// func AutomaticallyUpdateChannels(frequency int) {
|
||||
// if frequency <= 0 {
|
||||
// return
|
||||
// }
|
||||
|
||||
for {
|
||||
time.Sleep(time.Duration(frequency) * time.Minute)
|
||||
common.SysLog("updating all channels")
|
||||
_ = updateAllChannelsBalance()
|
||||
common.SysLog("channels update done")
|
||||
}
|
||||
}
|
||||
// for {
|
||||
// time.Sleep(time.Duration(frequency) * time.Minute)
|
||||
// common.SysLog("updating all channels")
|
||||
// _ = updateAllChannelsBalance()
|
||||
// common.SysLog("channels update done")
|
||||
// }
|
||||
// }
|
||||
|
18
main.go
18
main.go
@ -15,6 +15,7 @@ import (
|
||||
"one-api/model"
|
||||
"one-api/relay/util"
|
||||
"one-api/router"
|
||||
"time"
|
||||
|
||||
"github.com/gin-contrib/sessions"
|
||||
"github.com/gin-contrib/sessions/cookie"
|
||||
@ -71,10 +72,11 @@ func initMemoryCache() {
|
||||
common.SysLog("memory cache enabled")
|
||||
common.SysError(fmt.Sprintf("sync frequency: %d seconds", syncFrequency))
|
||||
go model.SyncOptions(syncFrequency)
|
||||
go SyncChannelCache(syncFrequency)
|
||||
}
|
||||
|
||||
func initSync() {
|
||||
go controller.AutomaticallyUpdateChannels(viper.GetInt("channel.update_frequency"))
|
||||
// go controller.AutomaticallyUpdateChannels(viper.GetInt("channel.update_frequency"))
|
||||
go controller.AutomaticallyTestChannels(viper.GetInt("channel.test_frequency"))
|
||||
}
|
||||
|
||||
@ -99,3 +101,17 @@ func initHttpServer() {
|
||||
common.FatalLog("failed to start HTTP server: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func SyncChannelCache(frequency int) {
|
||||
// 只有 从 服务器端获取数据的时候才会用到
|
||||
if common.IsMasterNode {
|
||||
common.SysLog("master node does't synchronize the channel")
|
||||
return
|
||||
}
|
||||
for {
|
||||
time.Sleep(time.Duration(frequency) * time.Second)
|
||||
common.SysLog("syncing channels from database")
|
||||
model.ChannelGroup.Load()
|
||||
util.PricingInstance.Init()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user