Bump version to 1.0.11
Machine status probe on page load: - POST /api/machines/refresh probes all machines in parallel (max 20 concurrent, 1.5s timeout) - Updates DB status and broadcasts via SSE to all connected browser tabs - Server-side throttle: ignores refresh requests within 10s - Machines.tsx and Dashboard.tsx fire probe on mount - Visual "Checking machine status..." indicator in Machines table - MachineHandler now accepts *Engine for ProbeAllMachines access
This commit is contained in:
@@ -17,12 +17,13 @@ import (
|
||||
)
|
||||
|
||||
type Engine struct {
|
||||
db *sql.DB
|
||||
cfg *config.Config
|
||||
queue *Queue
|
||||
eventBus *EventBus
|
||||
mu sync.RWMutex
|
||||
stopped bool
|
||||
db *sql.DB
|
||||
cfg *config.Config
|
||||
queue *Queue
|
||||
eventBus *EventBus
|
||||
mu sync.RWMutex
|
||||
stopped bool
|
||||
lastProbeAt atomic.Int64
|
||||
}
|
||||
|
||||
type Event struct {
|
||||
@@ -333,3 +334,51 @@ func (e *Engine) CreateJob(syncPairID int64, triggerType string) (int64, error)
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
|
||||
const (
|
||||
probeThrottleSeconds = 10
|
||||
probeTimeout = 1500 * time.Millisecond
|
||||
probeMaxConcurrent = 20
|
||||
)
|
||||
|
||||
func (e *Engine) ProbeAllMachines() {
|
||||
now := time.Now().UnixNano()
|
||||
last := e.lastProbeAt.Load()
|
||||
|
||||
if now-last < int64(probeThrottleSeconds*time.Second) {
|
||||
slog.Debug("ProbeAllMachines: skipped (throttled)")
|
||||
return
|
||||
}
|
||||
if !e.lastProbeAt.CompareAndSwap(last, now) {
|
||||
return
|
||||
}
|
||||
|
||||
machineRepo := models.NewMachineRepository(e.db)
|
||||
ms, err := machineRepo.GetAll()
|
||||
if err != nil {
|
||||
slog.Warn("ProbeAllMachines: list failed", "error", err)
|
||||
return
|
||||
}
|
||||
|
||||
sem := make(chan struct{}, probeMaxConcurrent)
|
||||
var wg sync.WaitGroup
|
||||
|
||||
for i := range ms {
|
||||
wg.Add(1)
|
||||
sem <- struct{}{}
|
||||
go func(m *models.Machine) {
|
||||
defer wg.Done()
|
||||
defer func() { <-sem }()
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), probeTimeout)
|
||||
defer cancel()
|
||||
|
||||
status := "offline"
|
||||
if wol.IsReachable(ctx, m.Host, m.Port, probeTimeout) {
|
||||
status = "online"
|
||||
}
|
||||
e.setMachineStatus(m.ID, status)
|
||||
}(&ms[i])
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user