You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

batch_check_package_redudancy.go 1.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package tickevent
  2. import (
  3. "time"
  4. "gitlink.org.cn/cloudream/common/pkgs/logger"
  5. "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/mq/scanner/event"
  6. evt "gitlink.org.cn/cloudream/jcs-pub/scanner/internal/event"
  7. )
  8. const (
  9. CheckPackageBatchSize = 100
  10. )
  11. type BatchCheckPackageRedundancy struct {
  12. lastCheckStart int
  13. }
  14. func NewBatchCheckPackageRedundancy() *BatchCheckPackageRedundancy {
  15. return &BatchCheckPackageRedundancy{}
  16. }
  17. func (e *BatchCheckPackageRedundancy) Execute(ctx ExecuteContext) {
  18. log := logger.WithType[BatchCheckPackageRedundancy]("TickEvent")
  19. log.Debugf("begin")
  20. defer log.Debugf("end")
  21. // TODO 更好的策略
  22. nowHour := time.Now().Hour()
  23. if nowHour > 6 {
  24. return
  25. }
  26. packageIDs, err := ctx.Args.DB.Package().BatchGetAllPackageIDs(ctx.Args.DB.DefCtx(), e.lastCheckStart, CheckPackageBatchSize)
  27. if err != nil {
  28. log.Warnf("batch get package ids failed, err: %s", err.Error())
  29. return
  30. }
  31. for _, id := range packageIDs {
  32. ctx.Args.EventExecutor.Post(evt.NewCheckPackageRedundancy(event.NewCheckPackageRedundancy(id)))
  33. }
  34. // 如果结果的长度小于预期的长度,则认为已经查询了所有,下次从头再来
  35. if len(packageIDs) < CheckPackageBatchSize {
  36. e.lastCheckStart = 0
  37. log.Debugf("all package checked, next time will start check at offset 0")
  38. } else {
  39. e.lastCheckStart += CheckPackageBatchSize
  40. }
  41. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。