Sha256: da7c70ac9a9f23dc5ba325a8b9ca44db30fd02f5fea4d70e61f0a42ccaafc166

Contents?: true

Size: 1.89 KB

Versions: 33

Compression:

Stored size: 1.89 KB

Contents

{"version":3,"file":"watchdog.js","sourceRoot":"","sources":["../../src/watchdog.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,gEAAgE;AAChE,uCAAuC;AAEvC,OAAO,EAAgB,KAAK,EAAE,MAAM,eAAe,CAAA;AAEnD,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;CAqB9B,CAAA;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAmB,EAAE,EAAE;IAC9C,IAAI,SAAS,GAAG,KAAK,CAAA;IACrB,MAAM,GAAG,GAAG,KAAK,CACf,OAAO,CAAC,QAAQ,EAChB,CAAC,IAAI,EAAE,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EACvC;QACE,KAAK,EAAE,QAAQ;KAChB,CACF,CAAA;IACD,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,CAAA;IACxC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;QACpB,IAAI,CAAC,SAAS;YAAE,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IACrC,CAAC,CAAC,CAAA;IACF,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA","sourcesContent":["// this spawns a child process that listens for SIGHUP when the\n// parent process exits, and after 200ms, sends a SIGKILL to the\n// child, in case it did not terminate.\n\nimport { ChildProcess, spawn } from 'child_process'\n\nconst watchdogCode = String.raw`\nconst pid = parseInt(process.argv[1], 10)\nprocess.title = 'node (foreground-child watchdog pid=' + pid + ')'\nif (!isNaN(pid)) {\n  let barked = false\n  // keepalive\n  const interval = setInterval(() => {}, 60000)\n  const bark = () => {\n    clearInterval(interval)\n    if (barked) return\n    barked = true\n    process.removeListener('SIGHUP', bark)\n    setTimeout(() => {\n      try {\n        process.kill(pid, 'SIGKILL')\n        setTimeout(() => process.exit(), 200)\n      } catch (_) {}\n    }, 500)\n  })\n  process.on('SIGHUP', bark)\n}\n`\n\nexport const watchdog = (child: ChildProcess) => {\n  let dogExited = false\n  const dog = spawn(\n    process.execPath,\n    ['-e', watchdogCode, String(child.pid)],\n    {\n      stdio: 'ignore',\n    }\n  )\n  dog.on('exit', () => (dogExited = true))\n  child.on('exit', () => {\n    if (!dogExited) dog.kill('SIGTERM')\n  })\n  return dog\n}\n"]}

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
immosquare-cleaner-0.1.60 node_modules/foreground-child/dist/mjs/watchdog.js.map
immosquare-cleaner-0.1.59 node_modules/foreground-child/dist/mjs/watchdog.js.map
immosquare-cleaner-0.1.58 node_modules/foreground-child/dist/mjs/watchdog.js.map
immosquare-cleaner-0.1.57 node_modules/foreground-child/dist/mjs/watchdog.js.map
immosquare-cleaner-0.1.56 node_modules/foreground-child/dist/mjs/watchdog.js.map
immosquare-cleaner-0.1.55 node_modules/foreground-child/dist/mjs/watchdog.js.map
immosquare-cleaner-0.1.54 node_modules/foreground-child/dist/mjs/watchdog.js.map
immosquare-cleaner-0.1.53 node_modules/foreground-child/dist/mjs/watchdog.js.map
immosquare-cleaner-0.1.52 node_modules/foreground-child/dist/mjs/watchdog.js.map
immosquare-cleaner-0.1.51 node_modules/foreground-child/dist/mjs/watchdog.js.map
immosquare-cleaner-0.1.50 node_modules/foreground-child/dist/mjs/watchdog.js.map
immosquare-cleaner-0.1.49 node_modules/foreground-child/dist/mjs/watchdog.js.map
immosquare-cleaner-0.1.48 node_modules/foreground-child/dist/mjs/watchdog.js.map
immosquare-cleaner-0.1.47 node_modules/foreground-child/dist/mjs/watchdog.js.map
immosquare-cleaner-0.1.46 node_modules/foreground-child/dist/mjs/watchdog.js.map
immosquare-cleaner-0.1.45 node_modules/foreground-child/dist/mjs/watchdog.js.map
immosquare-cleaner-0.1.44 node_modules/foreground-child/dist/mjs/watchdog.js.map
immosquare-cleaner-0.1.43 node_modules/foreground-child/dist/mjs/watchdog.js.map
immosquare-cleaner-0.1.42 node_modules/foreground-child/dist/mjs/watchdog.js.map
immosquare-cleaner-0.1.41 node_modules/foreground-child/dist/mjs/watchdog.js.map