pcm-octopus/internal/logic/gettrainjobmetriclogic.go

56 lines
1.4 KiB
Go

package logic
import (
"context"
"errors"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-octopus/internal/common"
"gitlink.org.cn/JointCloud/pcm-octopus/internal/svc"
"gitlink.org.cn/JointCloud/pcm-octopus/octopus"
"log"
"strconv"
)
type GetTrainJobMetricLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetTrainJobMetricLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTrainJobMetricLogic {
return &GetTrainJobMetricLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *GetTrainJobMetricLogic) GetTrainJobMetric(in *octopus.GetTrainJobMetricReq) (*octopus.GetTrainJobMetricResp, error) {
resp := &octopus.GetTrainJobMetricResp{}
var url_prefix = common.OctopusUrls[in.Platform]
var reqUrl = url_prefix + l.svcCtx.Config.OctopusApi.GetTrainJobMetric
token := common.GetToken(in.Platform)
if token == "" {
log.Println("获取token失败, platform : ", in.Platform)
return nil, errors.New("获取token失败")
}
req := common.GetRestyRequest()
_, err := req.
SetHeader("Authorization", "Bearer "+token).
SetQueryString("id=" + in.Id).
SetQueryString("start=" + strconv.Itoa(int(in.Start))).
SetQueryString("size=" + strconv.Itoa(int(in.Size))).
SetQueryString("step=" + strconv.Itoa(int(in.Step))).
SetResult(resp).
Get(reqUrl)
if err != nil {
return nil, err
}
return resp, nil
}