rosbag_clean.go 985 B

123456789101112131415161718192021222324252627282930
  1. package svc
  2. import (
  3. "cicv-data-closedloop/pji/common/cfg"
  4. "cicv-data-closedloop/pji/common/log"
  5. "cicv-data-closedloop/pji/common/util"
  6. "time"
  7. )
  8. // BagCacheClean 保证本地缓存的包数量不超过设定值
  9. func BagCacheClean() {
  10. log.GlobalLogger.Info("启动清理缓存的 goroutine 维护目录【", cfg.CloudConfig.BagDataDir, "】的 bag 包数量:", cfg.CloudConfig.BagNumber)
  11. for {
  12. // 收到自杀信号
  13. if signal := <-ChannelKillDiskClean; signal == 1 {
  14. AddKillTimes("2")
  15. return
  16. }
  17. // 1 ------- 每10秒清理一次 -------
  18. time.Sleep(time.Duration(500) * time.Millisecond)
  19. // 2 ------- 获取目录下所有bag包 -------
  20. bags := util.ListAbsolutePathWithSuffixAndSort(cfg.CloudConfig.BagDataDir, ".bag")
  21. // 3 如果打包数量超过n个,删除最旧的包{
  22. if len(bags) > cfg.CloudConfig.BagNumber {
  23. log.GlobalLogger.Infof("目录【%v】内文件数量超过【%v】,删除第一个文件")
  24. util.DeleteFile(bags[0])
  25. }
  26. }
  27. }