Skip to content

Commit

Permalink
Merge 5c3082d into 19bb3e6
Browse files Browse the repository at this point in the history
  • Loading branch information
dangra authored Jan 13, 2025
2 parents 19bb3e6 + 5c3082d commit 8b18d2a
Showing 1 changed file with 13 additions and 39 deletions.
52 changes: 13 additions & 39 deletions internal/command/deploy/machines_releasecommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/logrusorgru/aurora"
"github.com/samber/lo"
"github.com/sourcegraph/conc/pool"
fly "github.com/superfly/fly-go"
"github.com/superfly/fly-go/flaps"
"github.com/superfly/flyctl/helpers"
Expand Down Expand Up @@ -211,22 +212,21 @@ func dedicatedHostIdMismatch(m *fly.Machine, ac *appconfig.Config) bool {
func (md *machineDeployment) createOrUpdateReleaseCmdMachine(ctx context.Context) error {
span := trace.SpanFromContext(ctx)

if md.releaseCommandMachine.IsEmpty() {
return md.createReleaseCommandMachine(ctx)
}

releaseCmdMachine := md.releaseCommandMachine.GetMachines()[0]

if dedicatedHostIdMismatch(releaseCmdMachine.Machine(), md.appConfig) {
span.AddEvent("dedicated hostid mismatch")
if err := releaseCmdMachine.Destroy(ctx, true); err != nil {
return fmt.Errorf("error destroying release_command machine: %w", err)
// Existent release command machines must be destroyed if failed for some releaseCommandMachine
// They are set as auto-destroy anyways.
if !md.releaseCommandMachine.IsEmpty() {
mPool := pool.New().WithErrors().WithMaxGoroutines(4).WithContext(ctx)
for _, m := range md.releaseCommandMachine.GetMachines() {
mPool.Go(func(ctx context.Context) error {
return m.Destroy(ctx, true)
})
}
if err := mPool.Wait(); err != nil {
tracing.RecordError(span, err, "failed to destroy old release_command machine")
}

return md.createReleaseCommandMachine(ctx)
}

return md.updateReleaseCommandMachine(ctx)
return md.createReleaseCommandMachine(ctx)
}

func (md *machineDeployment) createReleaseCommandMachine(ctx context.Context) error {
Expand All @@ -252,32 +252,6 @@ func (md *machineDeployment) createReleaseCommandMachine(ctx context.Context) er
return nil
}

func (md *machineDeployment) updateReleaseCommandMachine(ctx context.Context) error {
ctx, span := tracing.GetTracer().Start(ctx, "update_release_cmd_machine")
defer span.End()

releaseCmdMachine := md.releaseCommandMachine.GetMachines()[0]
fmt.Fprintf(md.io.ErrOut, " Updating release_command machine %s\n", md.colorize.Bold(releaseCmdMachine.Machine().ID))

if err := releaseCmdMachine.WaitForState(ctx, fly.MachineStateStopped, md.waitTimeout, false); err != nil {
err = suggestChangeWaitTimeout(err, "wait-timeout")
return err
}

if err := md.releaseCommandMachine.AcquireLeases(ctx, md.leaseTimeout); err != nil {
return err
}
defer md.releaseCommandMachine.ReleaseLeases(ctx) // skipcq: GO-S2307
md.releaseCommandMachine.StartBackgroundLeaseRefresh(ctx, md.leaseTimeout, md.leaseDelayBetween)

launchInput := md.launchInputForReleaseCommand(releaseCmdMachine.Machine())
if err := releaseCmdMachine.Update(ctx, *launchInput); err != nil {
return fmt.Errorf("error updating release_command machine: %w", err)
}

return nil
}

func (md *machineDeployment) launchInputForReleaseCommand(origMachineRaw *fly.Machine) *fly.LaunchMachineInput {
if origMachineRaw == nil {
origMachineRaw = &fly.Machine{
Expand Down

0 comments on commit 8b18d2a

Please sign in to comment.