rosbag_clean.go 1015 B

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