(ctx context.Context, apiClient client.APIClient, containerID string, waitRemove bool)
| 10 | ) |
| 11 | |
| 12 | func waitExitOrRemoved(ctx context.Context, apiClient client.APIClient, containerID string, waitRemove bool) <-chan int { |
| 13 | if len(containerID) == 0 { |
| 14 | // containerID can never be empty |
| 15 | panic("Internal Error: waitExitOrRemoved needs a containerID as parameter") |
| 16 | } |
| 17 | |
| 18 | condition := container.WaitConditionNextExit |
| 19 | if waitRemove { |
| 20 | condition = container.WaitConditionRemoved |
| 21 | } |
| 22 | |
| 23 | waitRes := apiClient.ContainerWait(ctx, containerID, client.ContainerWaitOptions{ |
| 24 | Condition: condition, |
| 25 | }) |
| 26 | |
| 27 | statusC := make(chan int) |
| 28 | go func() { |
| 29 | defer close(statusC) |
| 30 | select { |
| 31 | case <-ctx.Done(): |
| 32 | return |
| 33 | case result := <-waitRes.Result: |
| 34 | if result.Error != nil { |
| 35 | logrus.Errorf("Error waiting for container: %v", result.Error.Message) |
| 36 | statusC <- 125 |
| 37 | } else { |
| 38 | statusC <- int(result.StatusCode) |
| 39 | } |
| 40 | case err := <-waitRes.Error: |
| 41 | if errors.Is(err, context.Canceled) { |
| 42 | return |
| 43 | } |
| 44 | logrus.Errorf("error waiting for container: %v", err) |
| 45 | statusC <- 125 |
| 46 | } |
| 47 | }() |
| 48 | |
| 49 | return statusC |
| 50 | } |
| 51 | |
| 52 | func parallelOperation(ctx context.Context, containers []string, op func(ctx context.Context, containerID string) error) chan error { |
| 53 | if len(containers) == 0 { |
searching dependent graphs…