(ctx context.Context, appName, oneOffLabel string)
| 11 | ) |
| 12 | |
| 13 | func OneOffStop(ctx context.Context, appName, oneOffLabel string) error { |
| 14 | c, err := config.ScalingoClient(ctx) |
| 15 | if err != nil { |
| 16 | return errors.Wrapf(ctx, err, "fail to get Scalingo client to stop a running one-off") |
| 17 | } |
| 18 | |
| 19 | containers, err := c.AppsContainersPs(ctx, appName) |
| 20 | if err != nil { |
| 21 | return errors.Wrapf(ctx, err, "fail to list the application containers to get the ID of the container to stop") |
| 22 | } |
| 23 | |
| 24 | var containerToStop *scalingo.Container |
| 25 | for _, container := range containers { |
| 26 | if container.Label == oneOffLabel { |
| 27 | containerToStop = &container |
| 28 | break |
| 29 | } |
| 30 | } |
| 31 | if containerToStop == nil { |
| 32 | return fmt.Errorf("The container '%s' does not exist", oneOffLabel) |
| 33 | } |
| 34 | |
| 35 | err = c.ContainersStop(ctx, appName, containerToStop.ID) |
| 36 | if err != nil { |
| 37 | return errors.Wrapf(ctx, err, "fail to stop the container '%s'", oneOffLabel) |
| 38 | } |
| 39 | |
| 40 | io.Statusf("Container one-off %v of the app %v is being asynchronously stopped...\n", io.Bold(containerToStop.Label), io.Bold(appName)) |
| 41 | |
| 42 | return nil |
| 43 | } |
no test coverage detected