Browse Source

更新StorageObject之后投递CheckObject任务

gitlink
Sydonian 2 years ago
parent
commit
3715d53db7
2 changed files with 7 additions and 2 deletions
  1. +1
    -2
      internal/event/check_object.go
  2. +6
    -0
      internal/event/update_storage.go

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

@@ -3,7 +3,6 @@ package event
import ( import (
"github.com/samber/lo" "github.com/samber/lo"
"gitlink.org.cn/cloudream/common/utils/logger" "gitlink.org.cn/cloudream/common/utils/logger"
mysql "gitlink.org.cn/cloudream/db/sql"
scevt "gitlink.org.cn/cloudream/rabbitmq/message/scanner/event" scevt "gitlink.org.cn/cloudream/rabbitmq/message/scanner/event"
) )


@@ -29,7 +28,7 @@ func (t *CheckObject) TryMerge(other Event) bool {


func (t *CheckObject) Execute(execCtx ExecuteContext) { func (t *CheckObject) Execute(execCtx ExecuteContext) {
for _, objID := range t.ObjectIDs { for _, objID := range t.ObjectIDs {
err := mysql.Object.DeleteUnused(execCtx.Args.DB.SQLCtx(), objID)
err := execCtx.Args.DB.Object().DeleteUnused(execCtx.Args.DB.SQLCtx(), objID)
if err != nil { if err != nil {
logger.WithField("ObjectID", objID).Warnf("delete unused object failed, err: %s", err.Error()) logger.WithField("ObjectID", objID).Warnf("delete unused object failed, err: %s", err.Error())
} }


+ 6
- 0
internal/event/update_storage.go View File

@@ -41,6 +41,7 @@ func (t *UpdateStorage) Execute(execCtx ExecuteContext) {
logger.WithField("StorageID", t.StorageID).Warnf("change storage state failed, err: %s", err.Error()) logger.WithField("StorageID", t.StorageID).Warnf("change storage state failed, err: %s", err.Error())
} }


var chkObjIDs []int
for _, entry := range t.Entries { for _, entry := range t.Entries {
switch entry.Operation { switch entry.Operation {
case tskcst.UPDATE_STORAGE_DELETE: case tskcst.UPDATE_STORAGE_DELETE:
@@ -50,6 +51,7 @@ func (t *UpdateStorage) Execute(execCtx ExecuteContext) {
WithField("ObjectID", entry.ObjectID). WithField("ObjectID", entry.ObjectID).
Warnf("delete storage object failed, err: %s", err.Error()) Warnf("delete storage object failed, err: %s", err.Error())
} }
chkObjIDs = append(chkObjIDs, entry.ObjectID)


case tskcst.UPDATE_STORAGE_SET_NORMAL: case tskcst.UPDATE_STORAGE_SET_NORMAL:
err := mysql.StorageObject.SetStateNormal(execCtx.Args.DB.SQLCtx(), t.StorageID, entry.ObjectID, entry.UserID) err := mysql.StorageObject.SetStateNormal(execCtx.Args.DB.SQLCtx(), t.StorageID, entry.ObjectID, entry.UserID)
@@ -60,6 +62,10 @@ func (t *UpdateStorage) Execute(execCtx ExecuteContext) {
} }
} }
} }

if len(chkObjIDs) > 0 {
execCtx.Executor.Post(NewCheckObject(chkObjIDs))
}
} }


func init() { func init() {


Loading…
Cancel
Save