|
@@ -1,7 +1,7 @@
|
|
|
package svc
|
|
|
|
|
|
import (
|
|
|
- commonConfig "cicv-data-closedloop/pji/common/cfg"
|
|
|
+ "cicv-data-closedloop/pji/common/cfg"
|
|
|
"cicv-data-closedloop/pji/common/log"
|
|
|
"cicv-data-closedloop/pji/common/util"
|
|
|
"time"
|
|
@@ -9,24 +9,20 @@ import (
|
|
|
|
|
|
// BagCacheClean 保证本地缓存的包数量不超过设定值
|
|
|
func BagCacheClean() {
|
|
|
- log.GlobalLogger.Info("启动清理缓存的 goroutine 维护 data 目录内的 bag 包数量:", commonConfig.CloudConfig.BagNumber)
|
|
|
+ log.GlobalLogger.Info("启动清理缓存的 goroutine 维护 data 目录内的 bag 包数量:", cfg.CloudConfig.BagNumber)
|
|
|
for {
|
|
|
// 收到自杀信号
|
|
|
if signal := <-ChannelKillDiskClean; signal == 1 {
|
|
|
- AddKillTimes("2")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 1 ------- 每10秒清理一次 -------
|
|
|
- time.Sleep(time.Duration(10) * time.Second)
|
|
|
+ time.Sleep(time.Duration(500) * time.Millisecond)
|
|
|
// 2 ------- 获取目录下所有bag包 -------
|
|
|
- bags := util.ListAbsolutePathWithSuffixAndSort(commonConfig.CloudConfig.BagDataDir, ".bag")
|
|
|
+ bags := util.ListAbsolutePathWithSuffixAndSort(cfg.CloudConfig.BagDataDir, ".bag")
|
|
|
// 3 如果打包数量超过n个,删除最旧的包{
|
|
|
- if len(bags) > commonConfig.CloudConfig.BagNumber {
|
|
|
- diff := len(bags) - commonConfig.CloudConfig.BagNumber
|
|
|
- for i := 0; i < diff; i++ {
|
|
|
- util.DeleteFile(bags[i])
|
|
|
- }
|
|
|
+ if len(bags) > cfg.CloudConfig.BagNumber {
|
|
|
+ util.DeleteFile(bags[0])
|
|
|
}
|
|
|
}
|
|
|
}
|