57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package task
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"gitlink.org.cn/cloudream/common/pkgs/logger"
|
|
"gitlink.org.cn/cloudream/common/sdks/storage/cdsapi"
|
|
schglb "gitlink.org.cn/cloudream/scheduler/common/globals"
|
|
exectsk "gitlink.org.cn/cloudream/scheduler/common/pkgs/mq/executor/task"
|
|
)
|
|
|
|
type CacheMovePackage struct {
|
|
*exectsk.CacheMovePackage
|
|
}
|
|
|
|
func NewCacheMovePackage(info *exectsk.CacheMovePackage) *CacheMovePackage {
|
|
return &CacheMovePackage{
|
|
CacheMovePackage: info,
|
|
}
|
|
}
|
|
|
|
func (t *CacheMovePackage) Execute(task *Task, ctx TaskContext) {
|
|
log := logger.WithType[CacheMovePackage]("Task")
|
|
log.Debugf("begin with %v", logger.FormatStruct(t.CacheMovePackage))
|
|
defer log.Debugf("end")
|
|
|
|
err := t.do(ctx)
|
|
if err != nil {
|
|
task.SendStatus(exectsk.NewCacheMovePackageStatus(err.Error()))
|
|
} else {
|
|
task.SendStatus(exectsk.NewCacheMovePackageStatus(""))
|
|
}
|
|
}
|
|
|
|
func (t *CacheMovePackage) do(ctx TaskContext) error {
|
|
stgCli, err := schglb.CloudreamStoragePool.Acquire()
|
|
if err != nil {
|
|
return fmt.Errorf("new cloudream storage client: %w", err)
|
|
}
|
|
defer schglb.CloudreamStoragePool.Release(stgCli)
|
|
|
|
_, err = stgCli.CacheMovePackage(cdsapi.CacheMovePackageReq{
|
|
UserID: t.UserID,
|
|
PackageID: t.PackageID,
|
|
StorageID: t.StgID,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func init() {
|
|
Register(NewCacheMovePackage)
|
|
}
|