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

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

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.