Пример #1
0
func runDestroyUnits(args []string) (exit int) {
	if len(args) == 0 {
		stderr("No units given")
		return 0
	}

	units, err := findUnits(args)
	if err != nil {
		stderr("%v", err)
		return 1
	}

	for _, v := range units {
		err := cAPI.DestroyUnit(v.Name)
		if err != nil {
			// Ignore 'Unit does not exist' error
			if client.IsErrorUnitNotFound(err) {
				continue
			}
			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(v.Name)
				if err != nil {
					stderr("Error destroying units: %v", err)
					exit = 1
					break
				}

				if u == nil {
					break
				}
				time.Sleep(defaultSleepTime)
			}
		}

		stdout("Destroyed %s", v.Name)
	}
	return
}
Пример #2
0
Файл: fleet.go Проект: pulcy/j2
// destroyUnitWithRetry wraps DestroyUnit of the fleet API with a retry.
func (f *FleetTunnel) destroyUnitWithRetry(unitName string) (notFound bool, err error) {
	op := func() error {
		if err := f.cAPI.DestroyUnit(unitName); client.IsErrorUnitNotFound(err) {
			// Ignore 'Unit does not exist' error
			notFound = true
			return nil
		}
		return maskAny(err)
	}
	if err := backoff.Retry(op, backoff.NewExponentialBackOff()); err != nil {
		return notFound, maskAny(err)
	}
	return notFound, nil
}