Browse Source

增加分批检查Object状态的任务

gitlink
Sydonian 2 years ago
parent
commit
caf8c15212
2 changed files with 34 additions and 2 deletions
  1. +2
    -2
      internal/event/check_object.go
  2. +32
    -0
      internal/tickevent/batch_check_all_object.go

+ 2
- 2
internal/event/check_object.go View File

@@ -10,8 +10,8 @@ type CheckObject struct {
ObjectIDs []int
}

func NewCheckObject(objIDs []int) CheckObject {
return CheckObject{
func NewCheckObject(objIDs []int) *CheckObject {
return &CheckObject{
ObjectIDs: objIDs,
}
}


+ 32
- 0
internal/tickevent/batch_check_all_object.go View File

@@ -0,0 +1,32 @@
package tickevent

import (
"gitlink.org.cn/cloudream/common/utils/logger"
mysql "gitlink.org.cn/cloudream/db/sql"
"gitlink.org.cn/cloudream/scanner/internal/event"
)

const CHECK_OBJECT_BATCH_SIZE = 100

type BatchCheckObject struct {
lastCheckStart int
}

func (e *BatchCheckObject) Execute(ctx ExecuteContext) {
objectIDs, err := mysql.Object.BatchGetAllObjectIDs(ctx.Args.DB.SQLCtx(), e.lastCheckStart, CHECK_OBJECT_BATCH_SIZE)
if err != nil {
logger.Warnf("batch get object ids failed, err: %s", err.Error())
return
}

ctx.Args.EventExecutor.Post(event.NewCheckObject(objectIDs))

// 如果结果的长度小于预期的长度,则认为已经查询了所有,下次从头再来
if len(objectIDs) < CHECK_OBJECT_BATCH_SIZE {
e.lastCheckStart = 0
logger.Debugf("all object checked, next time will start check at 0")

} else {
e.lastCheckStart += CHECK_OBJECT_BATCH_SIZE
}
}

Loading…
Cancel
Save