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

57 lines
1.3 KiB
Go
Raw Normal View History

2023-08-23 16:17:33 +08:00
package task
import (
"fmt"
2024-11-08 15:13:08 +08:00
2023-08-23 16:17:33 +08:00
"gitlink.org.cn/cloudream/common/pkgs/logger"
2024-11-08 15:13:08 +08:00
"gitlink.org.cn/cloudream/common/sdks/storage/cdsapi"
2023-09-21 10:44:26 +08:00
schglb "gitlink.org.cn/cloudream/scheduler/common/globals"
2023-09-04 16:48:46 +08:00
exectsk "gitlink.org.cn/cloudream/scheduler/common/pkgs/mq/executor/task"
2023-08-23 16:17:33 +08:00
)
type CacheMovePackage struct {
*exectsk.CacheMovePackage
2023-08-23 16:17:33 +08:00
}
func NewCacheMovePackage(info *exectsk.CacheMovePackage) *CacheMovePackage {
2023-08-23 16:17:33 +08:00
return &CacheMovePackage{
CacheMovePackage: info,
2023-08-23 16:17:33 +08:00
}
}
func (t *CacheMovePackage) Execute(task *Task, ctx TaskContext) {
2023-08-23 16:17:33 +08:00
log := logger.WithType[CacheMovePackage]("Task")
2023-11-03 11:18:01 +08:00
log.Debugf("begin with %v", logger.FormatStruct(t.CacheMovePackage))
2023-08-23 16:17:33 +08:00
defer log.Debugf("end")
2023-12-06 09:46:48 +08:00
err := t.do(ctx)
2023-09-04 16:48:46 +08:00
if err != nil {
task.SendStatus(exectsk.NewCacheMovePackageStatus(err.Error()))
2023-09-04 16:48:46 +08:00
} else {
task.SendStatus(exectsk.NewCacheMovePackageStatus(""))
2023-09-04 16:48:46 +08:00
}
2023-08-23 16:17:33 +08:00
}
2023-12-06 09:46:48 +08:00
func (t *CacheMovePackage) do(ctx TaskContext) error {
2023-09-21 10:44:26 +08:00
stgCli, err := schglb.CloudreamStoragePool.Acquire()
2023-08-23 16:17:33 +08:00
if err != nil {
2023-12-06 09:46:48 +08:00
return fmt.Errorf("new cloudream storage client: %w", err)
2023-08-23 16:17:33 +08:00
}
2023-09-26 09:59:01 +08:00
defer schglb.CloudreamStoragePool.Release(stgCli)
2023-08-23 16:17:33 +08:00
2024-11-08 15:13:08 +08:00
_, err = stgCli.CacheMovePackage(cdsapi.CacheMovePackageReq{
UserID: t.UserID,
PackageID: t.PackageID,
2024-11-08 15:13:08 +08:00
StorageID: t.StgID,
2023-08-23 16:17:33 +08:00
})
if err != nil {
2023-12-06 09:46:48 +08:00
return err
}
2023-12-06 09:46:48 +08:00
return err
2023-08-23 16:17:33 +08:00
}
func init() {
Register(NewCacheMovePackage)
}