mirror of
https://github.com/yibaiba/hideck.git
synced 2026-12-05 16:02:17 +00:00
37 lines
860 B
Go
37 lines
860 B
Go
package api
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/yibaiba/hideck/internal/device"
|
|
)
|
|
|
|
func (s *Server) refreshManagedWorkerRuntime(expected *device.Worker, reason string) bool {
|
|
if s == nil || s.pool == nil || expected == nil {
|
|
return false
|
|
}
|
|
releaseMutation := s.pool.AcquireManagedDeviceMutation(expected.ID)
|
|
defer releaseMutation()
|
|
if s.pool.GetWorker(expected.ID) != expected {
|
|
return false
|
|
}
|
|
_ = expected.RefreshRuntime(nil, reason)
|
|
return true
|
|
}
|
|
|
|
func (s *Server) scheduleFlightModeRuntimeRefresh(worker *device.Worker, recoveringOnline bool) {
|
|
go func() {
|
|
s.refreshManagedWorkerRuntime(worker, "flight_mode_change")
|
|
if !recoveringOnline {
|
|
return
|
|
}
|
|
timer := time.NewTimer(3 * time.Second)
|
|
defer timer.Stop()
|
|
select {
|
|
case <-timer.C:
|
|
s.refreshManagedWorkerRuntime(worker, "flight_mode_recover")
|
|
case <-s.shutdownCh:
|
|
}
|
|
}()
|
|
}
|