pcm-coordinator/internal/logic/inference/startallbydeploytaskidlogic.go

50 lines
1.3 KiB
Go

package inference
import (
"context"
"errors"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"strconv"
)
type StartAllByDeployTaskIdLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewStartAllByDeployTaskIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StartAllByDeployTaskIdLogic {
return &StartAllByDeployTaskIdLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *StartAllByDeployTaskIdLogic) StartAllByDeployTaskId(req *types.StartAllByDeployTaskIdReq) (resp *types.StartAllByDeployTaskIdResp, err error) {
resp = &types.StartAllByDeployTaskIdResp{}
id, err := strconv.ParseInt(req.Id, 10, 64)
list, err := l.svcCtx.Scheduler.AiStorages.GetInstanceListByDeployTaskId(id)
if err != nil {
return nil, err
}
for _, ins := range list {
success := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[strconv.FormatInt(ins.AdapterId, 10)][strconv.FormatInt(ins.ClusterId, 10)].StartInferDeployInstance(l.ctx, ins.InstanceId)
if !success {
return nil, errors.New(ins.InstanceName + " start failed")
}
}
err = l.svcCtx.Scheduler.AiStorages.UpdateDeployTaskById(id)
if err != nil {
return nil, err
}
return resp, nil
}