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

Commit 90b717e

Browse files
author
Dongsu Park
committed
Merge pull request #1654 from endocode/dongsu/fleetctl-wait-time-ticker
fleetctl: use time ticker in waitForSystemdActiveState
2 parents 53ba925 + 3d22847 commit 90b717e

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

fleetctl/fleetctl.go

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,25 +1104,21 @@ func tryWaitForSystemdActiveState(units []string) (ret int) {
11041104
// active, retrying periodically until the unit gets active. It will retry
11051105
// up to maxAttempts.
11061106
func waitForSystemdActiveState(conn *sd_dbus.Conn, unitName string) (found bool, err error) {
1107-
found = false
1108-
var errAssert error
1109-
sleep := defaultSleepTime
1110-
maxAttempts := 3
1111-
for attempt := 0; attempt < maxAttempts; attempt++ {
1112-
found, errAssert = assertSystemdActiveState(conn, unitName)
1113-
if found && errAssert == nil {
1114-
break
1107+
return func() (found bool, errWait error) {
1108+
timeout := 15 * time.Second
1109+
alarm := time.After(timeout)
1110+
ticker := time.Tick(250 * time.Millisecond)
1111+
for {
1112+
select {
1113+
case <-alarm:
1114+
return false, fmt.Errorf("Failed to reach expected state within %v.", timeout)
1115+
case <-ticker:
1116+
if found, errA := assertSystemdActiveState(conn, unitName); found && errA == nil {
1117+
return found, nil
1118+
}
1119+
}
11151120
}
1116-
time.Sleep(sleep)
1117-
}
1118-
1119-
if found {
1120-
err = nil
1121-
} else {
1122-
err = fmt.Errorf("%v", errAssert)
1123-
}
1124-
1125-
return found, err
1121+
}()
11261122
}
11271123

11281124
// assertSystemdActiveState determines if a given systemd unit is actually

0 commit comments

Comments
 (0)