Files
brain/tools/secretary-spawn.mjs
T

16 lines
849 B
JavaScript

// tools/secretary-spawn.mjs
// «Выстрел» фон-воркера: detached + unref → процесс переживает выход хука, хук его не ждёт.
// Идемпотентность по факту: если воркер уже крутится, новый упрётся в замок темы и выйдет.
import { spawn as realSpawn } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
const here = dirname(fileURLToPath(import.meta.url));
const WORKER = join(here, 'secretary-worker.mjs');
export function spawnWorker(workDir, { spawnImpl = realSpawn } = {}) {
const child = spawnImpl(process.execPath, [WORKER, workDir], { detached: true, stdio: 'ignore' });
if (child && typeof child.unref === 'function') child.unref();
return child;
}