rosbag_clean.go 988 B

1234567891011121314151617181920212223242526272829303132
  1. package svc
  2. import (
  3. commonConfig "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 维护 data 目录内的 bag 包数量:", commonConfig.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(10) * time.Second)
  19. // 2 ------- 获取目录下所有bag包 -------
  20. bags := util.ListAbsolutePathWithSuffixAndSort(commonConfig.CloudConfig.BagDataDir, ".bag")
  21. // 3 如果打包数量超过n个,删除最旧的包{
  22. if len(bags) > commonConfig.CloudConfig.BagNumber {
  23. diff := len(bags) - commonConfig.CloudConfig.BagNumber
  24. for i := 0; i < diff; i++ {
  25. util.DeleteFile(bags[i])
  26. }
  27. }
  28. }
  29. }