MCPcopy Create free account
hub / github.com/VirtualHotBar/NetMount / startComponentWatchdog

Function startComponentWatchdog

src/controller/main.ts:253–334  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

251}
252
253function 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

Callers 1

initFunction · 0.85

Calls 4

rclone_api_noopFunction · 0.90
restartRcloneFunction · 0.90
openlist_api_pingFunction · 0.90
restartOpenlistFunction · 0.90

Tested by

no test coverage detected