()
| 251 | } |
| 252 | |
| 253 | function startComponentWatchdog() { |
| 254 | componentWatchdogStopping = false |
| 255 | if (componentWatchdogTimer) { |
| 256 | clearInterval(componentWatchdogTimer) |
| 257 | componentWatchdogTimer = undefined |
| 258 | } |
| 259 | |
| 260 | let running = false |
| 261 | let rcloneFailCount = 0 |
| 262 | let openlistFailCount = 0 |
| 263 | let rcloneCooldownUntil = 0 |
| 264 | let openlistCooldownUntil = 0 |
| 265 | |
| 266 | const COOLDOWN_MS = 60_000 |
| 267 | const INTERVAL_MS = 10_000 |
| 268 | const FAIL_THRESHOLD = 3 |
| 269 | |
| 270 | componentWatchdogTimer = window.setInterval(async () => { |
| 271 | if (componentWatchdogStopping) return |
| 272 | if (!nmConfig.settings.autoRecoverComponents) return |
| 273 | if (running) return |
| 274 | running = true |
| 275 | |
| 276 | try { |
| 277 | const now = Date.now() |
| 278 | |
| 279 | if (rcloneInfo.process.child) { |
| 280 | const ok = await rclone_api_noop() |
| 281 | rcloneFailCount = ok ? 0 : rcloneFailCount + 1 |
| 282 | if (!ok && rcloneFailCount >= FAIL_THRESHOLD && now >= rcloneCooldownUntil) { |
| 283 | rcloneCooldownUntil = now + COOLDOWN_MS |
| 284 | rcloneFailCount = 0 |
| 285 | Notification.warning({ |
| 286 | id: 'rclone_auto_recover', |
| 287 | title: t('transmit'), |
| 288 | content: t('rclone_restarting'), |
| 289 | }) |
| 290 | try { |
| 291 | await restartRclone() |
| 292 | Notification.success({ |
| 293 | id: 'rclone_auto_recover_ok', |
| 294 | title: t('success'), |
| 295 | content: t('rclone_restarted'), |
| 296 | }) |
| 297 | } catch (e) { |
| 298 | console.error('restartRclone failed:', e) |
| 299 | } |
| 300 | } |
| 301 | } else { |
| 302 | rcloneFailCount = 0 |
| 303 | } |
| 304 | |
| 305 | if (openlistInfo.process.child) { |
| 306 | const ok = await openlist_api_ping() |
| 307 | openlistFailCount = ok ? 0 : openlistFailCount + 1 |
| 308 | if (!ok && openlistFailCount >= FAIL_THRESHOLD && now >= openlistCooldownUntil) { |
| 309 | openlistCooldownUntil = now + COOLDOWN_MS |
| 310 | openlistFailCount = 0 |
no test coverage detected