(ctx context.Context, serviceId string, id string)
| 566 | } |
| 567 | |
| 568 | func (i *imlPublishModule) Publish(ctx context.Context, serviceId string, id string) error { |
| 569 | _, err := i.serviceService.Check(ctx, serviceId, asServer) |
| 570 | if err != nil { |
| 571 | return err |
| 572 | } |
| 573 | flow, err := i.publishService.Get(ctx, id) |
| 574 | if err != nil { |
| 575 | return err |
| 576 | } |
| 577 | if flow.Service != serviceId { |
| 578 | return errors.New("服务不一致") |
| 579 | } |
| 580 | if flow.Status != publish.StatusAccept && flow.Status != publish.StatusDone { |
| 581 | return errors.New("只有通过状态才能发布") |
| 582 | } |
| 583 | clusters, err := i.clusterService.List(ctx) |
| 584 | if err != nil { |
| 585 | return err |
| 586 | } |
| 587 | clusterIds := utils.SliceToSlice(clusters, func(i *cluster.Cluster) string { |
| 588 | return i.Uuid |
| 589 | }) |
| 590 | |
| 591 | projectReleaseMap, err := i.getReleaseInfo(ctx, serviceId, flow.Release, flow.Release, clusterIds) |
| 592 | if err != nil { |
| 593 | return err |
| 594 | } |
| 595 | hasError := false |
| 596 | return i.transaction.Transaction(ctx, func(ctx context.Context) error { |
| 597 | for _, c := range clusters { |
| 598 | err = i.publish(ctx, flow.Id, c.Uuid, projectReleaseMap[c.Uuid]) |
| 599 | if err != nil { |
| 600 | hasError = true |
| 601 | log.Error(err) |
| 602 | continue |
| 603 | } |
| 604 | } |
| 605 | err = i.releaseService.SetRunning(ctx, serviceId, flow.Release) |
| 606 | if err != nil { |
| 607 | return err |
| 608 | } |
| 609 | status := publish.StatusDone |
| 610 | if hasError { |
| 611 | status = publish.StatusPublishError |
| 612 | } |
| 613 | if status == publish.StatusDone { |
| 614 | info, err := i.serviceService.Get(ctx, serviceId) |
| 615 | if err != nil { |
| 616 | return err |
| 617 | } |
| 618 | |
| 619 | apiDocCommit, err := i.apiDocService.LatestDocCommit(ctx, serviceId) |
| 620 | if err != nil { |
| 621 | return err |
| 622 | } |
| 623 | isReleased := true |
| 624 | i.serviceOverviewService.Update(ctx, serviceId, &service_overview.Update{ |
| 625 | ReleaseApiCount: &apiDocCommit.Data.APICount, |
nothing calls this directly
no test coverage detected