package svc import ( commonConfig "cicv-data-closedloop/pji/common/cfg" "cicv-data-closedloop/pji/common/log" "cicv-data-closedloop/pji/common/util" "time" ) // BagCacheClean 保证本地缓存的包数量不超过设定值 func BagCacheClean() { log.GlobalLogger.Info("启动清理缓存的 goroutine 维护 data 目录内的 bag 包数量:", commonConfig.CloudConfig.BagNumber) for { // 收到自杀信号 if signal := <-ChannelKillDiskClean; signal == 1 { AddKillTimes("2") return } // 1 ------- 每10秒清理一次 ------- time.Sleep(time.Duration(10) * time.Second) // 2 ------- 获取目录下所有bag包 ------- bags := util.ListAbsolutePathWithSuffixAndSort(commonConfig.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]) } } } }