improve ShutdownDevice func

This commit is contained in:
Maxi Quoß
2023-01-28 13:57:46 +01:00
parent 465407fbc2
commit 3d0ad679ee
2 changed files with 13 additions and 8 deletions

View File

@@ -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")
}

View File

@@ -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")
}