Skip to content

Commit

Permalink
fleetctl: block while destroying units to ensure units are destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Owens committed Aug 13, 2015
1 parent 431e169 commit 9530eed
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions fleetctl/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

package main

import (
"time"
)

var cmdDestroyUnit = &Command{
Name: "destroy",
Summary: "Destroy one or more units in the cluster",
Expand All @@ -33,9 +37,39 @@ func runDestroyUnits(args []string) (exit int) {
name := unitNameMangle(v)
err := cAPI.DestroyUnit(name)
if err != nil {
stderr("Error destroying units: %v", err)
exit = 1
continue
}

if !sharedFlags.NoBlock {
attempts := sharedFlags.BlockAttempts
retry := func() bool {
if sharedFlags.BlockAttempts < 1 {
return true
}
attempts--
if attempts == 0 {
return false
}
return true
}

for retry() {
u, err := cAPI.Unit(name)
if err != nil {
stderr("Error destroying units: %v", err)
exit = 1
break
}

if u == nil {
break
}
time.Sleep(500 * time.Millisecond)
}
}

stdout("Destroyed %s", name)
}
return
Expand Down

0 comments on commit 9530eed

Please sign in to comment.