66 lines
2.7 KiB
Go
66 lines
2.7 KiB
Go
package services
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gitlink.org.cn/cloudream/common/pkgs/mq"
|
|
execmq "gitlink.org.cn/cloudream/scheduler/common/pkgs/mq/executor"
|
|
schtsk "gitlink.org.cn/cloudream/scheduler/executor/internal/task"
|
|
)
|
|
|
|
func (svc *Service) StartStorageLoadPackage(msg *execmq.StartStorageLoadPackage) (*execmq.StartStorageLoadPackageResp, *mq.CodeMessage) {
|
|
tsk := svc.taskManager.StartNew(schtsk.NewStorageLoadPackage(msg.UserID, msg.PackageID, msg.StorageID))
|
|
return mq.ReplyOK(execmq.NewStartStorageLoadPackageResp(tsk.ID()))
|
|
}
|
|
|
|
func (svc *Service) WaitStorageLoadPackage(msg *execmq.WaitStorageLoadPackage) (*execmq.WaitStorageLoadPackageResp, *mq.CodeMessage) {
|
|
tsk := svc.taskManager.FindByID(msg.TaskID)
|
|
if tsk.WaitTimeout(time.Duration(msg.WaitTimeoutMs) * time.Millisecond) {
|
|
errMsg := ""
|
|
if tsk.Error() != nil {
|
|
errMsg = tsk.Error().Error()
|
|
}
|
|
|
|
return mq.ReplyOK(execmq.NewWaitStorageLoadPackageResp(true, errMsg))
|
|
}
|
|
return mq.ReplyOK(execmq.NewWaitStorageLoadPackageResp(false, ""))
|
|
}
|
|
|
|
func (svc *Service) StartStorageCreatePackage(msg *execmq.StartStorageCreatePackage) (*execmq.StartStorageCreatePackageResp, *mq.CodeMessage) {
|
|
tsk := svc.taskManager.StartNew(schtsk.NewStorageCreatePackage(msg.UserID, msg.StorageID, msg.Path, msg.BucketID, msg.Name, msg.Redundancy))
|
|
return mq.ReplyOK(execmq.NewStartStorageCreatePackageResp(tsk.ID()))
|
|
}
|
|
|
|
func (svc *Service) WaitStorageCreatePackage(msg *execmq.WaitStorageCreatePackage) (*execmq.WaitStorageCreatePackageResp, *mq.CodeMessage) {
|
|
tsk := svc.taskManager.FindByID(msg.TaskID)
|
|
if tsk.WaitTimeout(time.Duration(msg.WaitTimeoutMs) * time.Millisecond) {
|
|
tskBody := tsk.Body().(*schtsk.StorageCreatePackage)
|
|
|
|
errMsg := ""
|
|
if tsk.Error() != nil {
|
|
errMsg = tsk.Error().Error()
|
|
}
|
|
|
|
return mq.ReplyOK(execmq.NewWaitStorageCreatePackageResp(true, errMsg, tskBody.Result.PackageID))
|
|
}
|
|
return mq.ReplyOK(execmq.NewWaitStorageCreatePackageResp(false, "", 0))
|
|
}
|
|
|
|
func (svc *Service) StartCacheMovePackage(msg *execmq.StartCacheMovePackage) (*execmq.StartCacheMovePackageResp, *mq.CodeMessage) {
|
|
tsk := svc.taskManager.StartNew(schtsk.NewCacheMovePackage(msg.UserID, msg.PackageID, msg.NodeID))
|
|
return mq.ReplyOK(execmq.NewStartCacheMovePackageResp(tsk.ID()))
|
|
}
|
|
|
|
func (svc *Service) WaitCacheMovePackage(msg *execmq.WaitCacheMovePackage) (*execmq.WaitCacheMovePackageResp, *mq.CodeMessage) {
|
|
tsk := svc.taskManager.FindByID(msg.TaskID)
|
|
if tsk.WaitTimeout(time.Duration(msg.WaitTimeoutMs) * time.Millisecond) {
|
|
errMsg := ""
|
|
if tsk.Error() != nil {
|
|
errMsg = tsk.Error().Error()
|
|
}
|
|
|
|
return mq.ReplyOK(execmq.NewWaitCacheMovePackageResp(true, errMsg))
|
|
}
|
|
return mq.ReplyOK(execmq.NewWaitCacheMovePackageResp(false, ""))
|
|
}
|