package resource import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/grampus" "strings" ) func AddResourceQueue(req models.ResourceQueueReq) error { if _, err := models.InsertResourceQueue(req.ToDTO()); err != nil { return err } return nil } func UpdateResourceQueue(queueId int64, req models.ResourceQueueReq) error { if _, err := models.UpdateResourceQueueById(queueId, models.ResourceQueue{ CardsTotalNum: req.CardsTotalNum, Remark: req.Remark, }); err != nil { return err } return nil } func GetResourceQueueList(opts models.SearchResourceQueueOptions) (*models.ResourceQueueListRes, error) { n, r, err := models.SearchResourceQueue(opts) if err != nil { return nil, err } return models.NewResourceQueueListRes(n, r), nil } func GetResourceQueueCodes(opts models.GetQueueCodesOptions) ([]*models.ResourceQueueCodesRes, error) { r, err := models.GetResourceQueueCodes(opts) if err != nil { return nil, err } return r, nil } func GetResourceAiCenters() ([]models.ResourceAiCenterRes, error) { r, err := models.GetResourceAiCenters() if err != nil { return nil, err } return r, nil } func SyncGrampusQueue(doerId int64) error { r, err := grampus.GetAiCenters(1, 100) if err != nil { return err } queueUpdateList := make([]models.ResourceQueue, 0) queueInsertList := make([]models.ResourceQueue, 0) existIds := make([]int64, 0) for _, center := range r.Infos { for _, device := range center.AccDevices { computeResource := models.ParseComputeResourceFormGrampus(device.Kind) accCardType := strings.ToUpper(device.Model) if computeResource == "" { continue } //Determine if this quque already exists.if exist,update params //if not exist,insert a new record oldQueue, err := models.GetResourceQueue(&models.ResourceQueue{ Cluster: models.C2NetCluster, AiCenterCode: center.Id, ComputeResource: computeResource, AccCardType: accCardType, }) if err != nil { return err } if oldQueue == nil { queueInsertList = append(queueInsertList, models.ResourceQueue{ Cluster: models.C2NetCluster, AiCenterCode: center.Id, AiCenterName: center.Name, ComputeResource: computeResource, AccCardType: accCardType, IsAutomaticSync: true, CreatedBy: doerId, UpdatedBy: doerId, }) } else { existIds = append(existIds, oldQueue.ID) queueUpdateList = append(queueUpdateList, models.ResourceQueue{ ID: oldQueue.ID, ComputeResource: computeResource, AiCenterName: center.Name, AccCardType: accCardType, UpdatedBy: doerId, }) } } } //todo 调试两个虎鲸接口,注意批量update是否有问题。确定上架时有没有检查queue是否被删除 return models.SyncGrampusQueues(queueUpdateList, queueInsertList, existIds) }