-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
stop.go
46 lines (41 loc) · 1.16 KB
/
stop.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package ecsta
import (
"context"
"fmt"
"github.com/Songmu/prompter"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ecs"
)
type StopOption struct {
ID string `help:"task ID"`
Force bool `help:"stop without confirmation"`
Family *string `help:"task definition family name"`
Service *string `help:"ECS service name"`
}
func (app *Ecsta) RunStop(ctx context.Context, opt *StopOption) error {
if err := app.SetCluster(ctx); err != nil {
return err
}
task, err := app.findTask(ctx, &optionFindTask{
id: opt.ID, family: opt.Family, service: opt.Service,
selectFunc: selectFuncExcludeStopped,
})
if err != nil {
return fmt.Errorf("failed to select tasks: %w", err)
}
doStop := true
if !opt.Force {
doStop = prompter.YN(fmt.Sprintf("Do you request to stop a task %s?", arnToName(*task.TaskArn)), false)
}
if !doStop {
return ErrAborted
}
if _, err := app.ecs.StopTask(ctx, &ecs.StopTaskInput{
Cluster: &app.cluster,
Task: task.TaskArn,
Reason: aws.String("Request stop task by user action."),
}); err != nil {
return fmt.Errorf("failed to stop task %s: %w", arnToName(*task.TaskArn), err)
}
return nil
}