You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

deployinstancelistlogic.go 1.8 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package inference
  2. import (
  3. "context"
  4. "errors"
  5. "github.com/zeromicro/go-zero/core/logx"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/updater"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  9. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
  10. "time"
  11. )
  12. type DeployInstanceListLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. func NewDeployInstanceListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeployInstanceListLogic {
  18. return &DeployInstanceListLogic{
  19. Logger: logx.WithContext(ctx),
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. }
  23. }
  24. func (l *DeployInstanceListLogic) DeployInstanceList(req *types.DeployInstanceListReq) (resp *types.DeployInstanceListResp, err error) {
  25. limit := req.PageSize
  26. offset := req.PageSize * (req.PageNum - 1)
  27. resp = &types.DeployInstanceListResp{}
  28. var list []*models.AiInferDeployInstance
  29. tx := l.svcCtx.DbEngin.Raw("select * from ai_infer_deploy_instance").Scan(&list)
  30. if tx.Error != nil {
  31. logx.Errorf(tx.Error.Error())
  32. return nil, tx.Error
  33. }
  34. go updater.UpdateDeployInstanceStatusBatch(l.svcCtx, list)
  35. ins := list[0]
  36. for i := range list {
  37. uTime, _ := time.Parse(time.RFC3339, ins.UpdateTime)
  38. latest, _ := time.Parse(time.RFC3339, list[i].UpdateTime)
  39. if latest.After(uTime) {
  40. ins = list[i]
  41. }
  42. }
  43. go updater.UpdateDeployInstanceStatus(l.svcCtx, ins, true)
  44. //count total
  45. var total int64
  46. err = tx.Count(&total).Error
  47. tx.Limit(limit).Offset(offset)
  48. if err != nil {
  49. return resp, err
  50. }
  51. err = tx.Order("create_time desc").Find(&list).Error
  52. if err != nil {
  53. return nil, errors.New(err.Error())
  54. }
  55. resp.List = &list
  56. resp.PageSize = req.PageSize
  57. resp.PageNum = req.PageNum
  58. resp.Total = total
  59. return
  60. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.