Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1654 from endocode/dongsu/fleetctl-wait-time-ticker
Browse files Browse the repository at this point in the history
fleetctl: use time ticker in waitForSystemdActiveState
  • Loading branch information
Dongsu Park committed Aug 19, 2016
2 parents 53ba925 + 3d22847 commit 90b717e
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions fleetctl/fleetctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1104,25 +1104,21 @@ func tryWaitForSystemdActiveState(units []string) (ret int) {
// active, retrying periodically until the unit gets active. It will retry
// up to maxAttempts.
func waitForSystemdActiveState(conn *sd_dbus.Conn, unitName string) (found bool, err error) {
found = false
var errAssert error
sleep := defaultSleepTime
maxAttempts := 3
for attempt := 0; attempt < maxAttempts; attempt++ {
found, errAssert = assertSystemdActiveState(conn, unitName)
if found && errAssert == nil {
break
return func() (found bool, errWait error) {
timeout := 15 * time.Second
alarm := time.After(timeout)
ticker := time.Tick(250 * time.Millisecond)
for {
select {
case <-alarm:
return false, fmt.Errorf("Failed to reach expected state within %v.", timeout)
case <-ticker:
if found, errA := assertSystemdActiveState(conn, unitName); found && errA == nil {
return found, nil
}
}
}
time.Sleep(sleep)
}

if found {
err = nil
} else {
err = fmt.Errorf("%v", errAssert)
}

return found, err
}()
}

// assertSystemdActiveState determines if a given systemd unit is actually
Expand Down

0 comments on commit 90b717e

Please sign in to comment.