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