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.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. if len(list) == 0 {
  35. return
  36. }
  37. go updater.UpdateDeployInstanceStatusBatch(l.svcCtx, list)
  38. ins := list[0]
  39. for i := range list {
  40. uTime, _ := time.Parse(time.RFC3339, ins.UpdateTime)
  41. latest, _ := time.Parse(time.RFC3339, list[i].UpdateTime)
  42. if latest.After(uTime) {
  43. ins = list[i]
  44. }
  45. }
  46. go updater.UpdateDeployInstanceStatus(l.svcCtx, ins, true)
  47. go updater.UpdateDeployTaskStatus(l.svcCtx)
  48. //count total
  49. var total int64
  50. err = tx.Count(&total).Error
  51. tx.Limit(limit).Offset(offset)
  52. if err != nil {
  53. return resp, err
  54. }
  55. err = tx.Order("create_time desc").Find(&list).Error
  56. if err != nil {
  57. return nil, errors.New(err.Error())
  58. }
  59. resp.List = &list
  60. resp.PageSize = req.PageSize
  61. resp.PageNum = req.PageNum
  62. resp.Total = total
  63. return
  64. }

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.