-
Notifications
You must be signed in to change notification settings - Fork 220
/
update.go
46 lines (36 loc) · 1.12 KB
/
update.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 machine
import (
"context"
"fmt"
"time"
"github.com/superfly/flyctl/api"
"github.com/superfly/flyctl/flaps"
"github.com/superfly/flyctl/internal/watch"
"github.com/superfly/flyctl/iostreams"
)
func Update(ctx context.Context, m *api.Machine, input *api.LaunchMachineInput) error {
var (
flapsClient = flaps.FromContext(ctx)
io = iostreams.FromContext(ctx)
colorize = io.ColorScheme()
)
fmt.Fprintf(io.Out, "Updating machine %s\n", colorize.Bold(m.ID))
input.ID = m.ID
if _, err := flapsClient.Update(ctx, *input, m.LeaseNonce); err != nil {
return fmt.Errorf("could not stop machine %s: %w", input.ID, err)
}
waitForAction := "start"
if m.Config.Schedule != "" {
waitForAction = "stop"
}
if err := WaitForStartOrStop(ctx, &api.Machine{ID: input.ID}, waitForAction, time.Minute*5); err != nil {
return err
}
if !input.SkipHealthChecks {
if err := watch.MachinesChecks(ctx, []*api.Machine{m}); err != nil {
return fmt.Errorf("failed to wait for health checks to pass: %w", err)
}
}
fmt.Fprintf(io.Out, "Machine %s updated successfully!\n", colorize.Bold(m.ID))
return nil
}