(ctx context.Context, appName string, signal string, containerNames []string)
| 53 | } |
| 54 | |
| 55 | func SendSignal(ctx context.Context, appName string, signal string, containerNames []string) error { |
| 56 | if len(containerNames) == 0 { |
| 57 | return errors.New(ctx, "at least one container name should be given") |
| 58 | } |
| 59 | if signal == "" { |
| 60 | return errors.New(ctx, "signal must not be empty") |
| 61 | } |
| 62 | |
| 63 | c, err := config.ScalingoClient(ctx) |
| 64 | if err != nil { |
| 65 | return errors.Wrapf(ctx, err, "fail to get Scalingo client to send signal to application containers") |
| 66 | } |
| 67 | |
| 68 | containers, err := c.AppsContainersPs(ctx, appName) |
| 69 | if err != nil { |
| 70 | return errors.Wrapf(ctx, err, "fail to list the application containers to get the ID of the container to send the signal") |
| 71 | } |
| 72 | |
| 73 | containersToKill := keepUniqueContainersWithNames(ctx, containers, containerNames) |
| 74 | |
| 75 | for _, container := range containersToKill { |
| 76 | err := c.ContainersKill(ctx, appName, signal, container.ID) |
| 77 | if err != nil { |
| 78 | io.Errorf("Fail to send signal to container '%v' because of: %v\n", container.Label, err) |
| 79 | continue |
| 80 | } |
| 81 | io.Statusf("Sent signal '%v' to '%v' container.\n", signal, container.Label) |
| 82 | } |
| 83 | return nil |
| 84 | } |
no test coverage detected