JCC-CSScheduler/executor/internal/task/cache_move_package.go

60 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package task
import (
"fmt"
"time"
"gitlink.org.cn/cloudream/common/api/storage"
"gitlink.org.cn/cloudream/common/pkgs/logger"
"gitlink.org.cn/cloudream/common/pkgs/task"
"gitlink.org.cn/cloudream/scheduler/common/globals"
exectsk "gitlink.org.cn/cloudream/scheduler/common/pkgs/mq/executor/task"
)
type CacheMovePackage struct {
userID int64
packageID int64
stgNodeID int64
}
func NewCacheMovePackage(userID int64, packageID int64, stgNodeID int64) *CacheMovePackage {
return &CacheMovePackage{
userID: userID,
packageID: packageID,
stgNodeID: stgNodeID,
}
}
func (t *CacheMovePackage) Execute(task *task.Task[TaskContext], ctx TaskContext, complete CompleteFn) {
log := logger.WithType[CacheMovePackage]("Task")
log.Debugf("begin with %v", logger.FormatStruct(t))
defer log.Debugf("end")
err := t.do(ctx)
if err != nil {
//TODO 若任务失败上报的状态failed字段根据情况修改
ctx.reporter.Report(task.ID(), exectsk.NewCacheMovePackageTaskStatus("failed", err.Error()))
} else {
ctx.reporter.Report(task.ID(), exectsk.NewCacheMovePackageTaskStatus("completed", ""))
}
ctx.reporter.ReportNow()
complete(err, CompleteOption{
RemovingDelay: time.Minute,
})
}
func (t *CacheMovePackage) do(ctx TaskContext) error {
stgCli, err := globals.CloudreamStoragePool.Acquire()
if err != nil {
return fmt.Errorf("new cloudream storage client: %w", err)
}
defer stgCli.Close()
return stgCli.CacheMovePackage(storage.CacheMovePackageReq{
UserID: t.userID,
PackageID: t.packageID,
StgNodeID: t.stgNodeID,
})
}