MCPcopy Create free account
hub / github.com/Scalingo/cli / OneOffStop

Function OneOffStop

apps/one_off_stop.go:13–43  ·  view source on GitHub ↗
(ctx context.Context, appName, oneOffLabel string)

Source from the content-addressed store, hash-verified

11)
12
13func 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}

Callers 1

one_off_stop.goFile · 0.92

Calls 3

ScalingoClientFunction · 0.92
StatusfFunction · 0.92
BoldFunction · 0.92

Tested by

no test coverage detected