startAutoRefresh starts the auto-refresh timer.
()
| 34 | |
| 35 | // startAutoRefresh starts the auto-refresh timer. |
| 36 | func (a *App) startAutoRefresh() { |
| 37 | // Don't start if auto-refresh is not enabled |
| 38 | if !a.autoRefreshEnabled { |
| 39 | return |
| 40 | } |
| 41 | |
| 42 | if a.autoRefreshRunning { |
| 43 | return // Already running |
| 44 | } |
| 45 | |
| 46 | a.autoRefreshRunning = true |
| 47 | a.autoRefreshCountdown = 10 |
| 48 | a.footer.UpdateAutoRefreshCountdown(a.autoRefreshCountdown) |
| 49 | a.autoRefreshCountdownStop = make(chan bool, 1) |
| 50 | |
| 51 | // Start countdown goroutine using a proper ticker instead of busy-wait + sleep |
| 52 | go func() { |
| 53 | uiLogger := models.GetUILogger() |
| 54 | countdownTicker := time.NewTicker(1 * time.Second) |
| 55 | defer countdownTicker.Stop() |
| 56 | |
| 57 | for { |
| 58 | select { |
| 59 | case <-a.autoRefreshCountdownStop: |
| 60 | return |
| 61 | case <-a.ctx.Done(): |
| 62 | return |
| 63 | case <-countdownTicker.C: |
| 64 | if !a.autoRefreshEnabled { |
| 65 | return |
| 66 | } |
| 67 | |
| 68 | if a.footer.IsLoading() { |
| 69 | continue // Pause countdown while loading |
| 70 | } |
| 71 | |
| 72 | a.autoRefreshCountdown-- |
| 73 | if a.autoRefreshCountdown < 0 { |
| 74 | a.autoRefreshCountdown = 0 |
| 75 | } |
| 76 | |
| 77 | // Trigger refresh when countdown reaches 0 |
| 78 | if a.autoRefreshCountdown == 0 { |
| 79 | // Only refresh if not currently loading, no pending operations, |
| 80 | // and no other refresh (manual/fast/enrichment) is in progress. |
| 81 | if !a.header.IsLoading() && !models.GlobalState.HasPendingOperations() && !a.isRefreshActive() { |
| 82 | uiLogger.Debug("Auto-refresh triggered by countdown") |
| 83 | |
| 84 | go a.autoRefreshDataWithFooter() |
| 85 | } else { |
| 86 | if a.isRefreshActive() { |
| 87 | uiLogger.Debug("Auto-refresh skipped - refresh already in progress") |
| 88 | } else if a.header.IsLoading() { |
| 89 | uiLogger.Debug("Auto-refresh skipped - header loading operation in progress") |
| 90 | } else { |
| 91 | uiLogger.Debug("Auto-refresh skipped - pending VM/node operations in progress") |
| 92 | } |
| 93 | // Reset countdown to try again in 10 seconds |
no test coverage detected