mirror of
https://github.com/seriousm4x/UpSnap.git
synced 2026-07-22 21:43:42 -04:00
improve ShutdownDevice func
This commit is contained in:
@@ -17,12 +17,17 @@ func ShutdownDevice(device *models.Record) error {
|
||||
}
|
||||
}
|
||||
|
||||
// we wait 1 minute for the device to come up
|
||||
// after that, we check the state
|
||||
time.Sleep(1 * time.Minute)
|
||||
isOnline := PingDevice(device)
|
||||
if isOnline {
|
||||
return errors.New("device not offline after 1 min")
|
||||
// check state every second for 2 min
|
||||
start := time.Now()
|
||||
for {
|
||||
time.Sleep(1 * time.Second)
|
||||
isOnline := PingDevice(device)
|
||||
if !isOnline {
|
||||
return nil
|
||||
}
|
||||
if time.Since(start) >= 2*time.Minute {
|
||||
break
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return errors.New("device not offline after 2 min")
|
||||
}
|
||||
|
||||
@@ -25,5 +25,5 @@ func WakeDevice(device *models.Record) error {
|
||||
break
|
||||
}
|
||||
}
|
||||
return errors.New("device not online after 1 min")
|
||||
return errors.New("device not online after 2 min")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user