(ctx context.Context, id string, clusterId string, projectRelease *gateway.ProjectRelease)
| 516 | } |
| 517 | |
| 518 | func (i *imlPublishModule) publish(ctx context.Context, id string, clusterId string, projectRelease *gateway.ProjectRelease) error { |
| 519 | |
| 520 | publishStatus := &publish.Status{ |
| 521 | Publish: id, |
| 522 | Status: publish.StatusPublishing, |
| 523 | UpdateAt: time.Now(), |
| 524 | } |
| 525 | err := i.publishService.SetPublishStatus(ctx, publishStatus) |
| 526 | if err != nil { |
| 527 | return fmt.Errorf("set publishing publishStatus error: %v", err) |
| 528 | } |
| 529 | defer func() { |
| 530 | err := i.publishService.SetPublishStatus(ctx, publishStatus) |
| 531 | if err != nil { |
| 532 | log.Errorf("set publishing publishStatus error: %v", err) |
| 533 | } |
| 534 | }() |
| 535 | |
| 536 | client, err := i.clusterService.GatewayClient(ctx, clusterId) |
| 537 | if err != nil { |
| 538 | publishStatus.Status = publish.StatusPublishError |
| 539 | publishStatus.Error = err.Error() |
| 540 | publishStatus.UpdateAt = time.Now() |
| 541 | return fmt.Errorf("get gateway client error: %v", err) |
| 542 | } |
| 543 | defer func() { |
| 544 | err := client.Close(ctx) |
| 545 | if err != nil { |
| 546 | log.Warn("close apinto client:", err) |
| 547 | } |
| 548 | }() |
| 549 | err = client.Project().Online(ctx, projectRelease) |
| 550 | if err != nil { |
| 551 | publishStatus.Status = publish.StatusPublishError |
| 552 | publishStatus.Error = err.Error() |
| 553 | publishStatus.UpdateAt = time.Now() |
| 554 | return fmt.Errorf("online error: %v", err) |
| 555 | } |
| 556 | apiIds := utils.SliceToSlice(projectRelease.Apis, func(api *gateway.ApiRelease) string { |
| 557 | return api.ID |
| 558 | }) |
| 559 | client.Service().Online(ctx, &gateway.ServiceRelease{ |
| 560 | ID: projectRelease.Id, |
| 561 | Apis: apiIds, |
| 562 | }) |
| 563 | publishStatus.Status = publish.StatusDone |
| 564 | publishStatus.UpdateAt = time.Now() |
| 565 | return nil |
| 566 | } |
| 567 | |
| 568 | func (i *imlPublishModule) Publish(ctx context.Context, serviceId string, id string) error { |
| 569 | _, err := i.serviceService.Check(ctx, serviceId, asServer) |
no test coverage detected