(ctx context.Context, projectName string, options api.WaitOptions)
| 27 | ) |
| 28 | |
| 29 | func (s *composeService) Wait(ctx context.Context, projectName string, options api.WaitOptions) (int64, error) { |
| 30 | containers, err := s.getContainers(ctx, projectName, oneOffInclude, false, options.Services...) |
| 31 | if err != nil { |
| 32 | return 0, err |
| 33 | } |
| 34 | if len(containers) == 0 { |
| 35 | return 0, fmt.Errorf("no containers for project %q", projectName) |
| 36 | } |
| 37 | |
| 38 | eg, waitCtx := errgroup.WithContext(ctx) |
| 39 | var statusCode int64 |
| 40 | for _, ctr := range containers { |
| 41 | eg.Go(func() error { |
| 42 | var err error |
| 43 | res := s.apiClient().ContainerWait(waitCtx, ctr.ID, client.ContainerWaitOptions{}) |
| 44 | select { |
| 45 | case result := <-res.Result: |
| 46 | _, _ = fmt.Fprintf(s.stdout(), "container %q exited with status code %d\n", ctr.ID, result.StatusCode) |
| 47 | statusCode = result.StatusCode |
| 48 | case err = <-res.Error: |
| 49 | } |
| 50 | return err |
| 51 | }) |
| 52 | } |
| 53 | |
| 54 | err = eg.Wait() |
| 55 | if err != nil { |
| 56 | return 42, err // Ignore abort flag in case of error in wait |
| 57 | } |
| 58 | |
| 59 | if options.DownProjectOnContainerExit { |
| 60 | return statusCode, s.Down(ctx, projectName, api.DownOptions{ |
| 61 | RemoveOrphans: true, |
| 62 | }) |
| 63 | } |
| 64 | |
| 65 | return statusCode, err |
| 66 | } |
nothing calls this directly
no test coverage detected