Save job pid to the database and sing sigint to kill it when stopping so it stops immediatly.

This commit is contained in:
Jaret Burkett
2026-03-26 09:10:37 -06:00
parent 89d2090962
commit 4df3b0463f
4 changed files with 49 additions and 8 deletions

View File

@@ -125,18 +125,25 @@ const startAndWatchJob = (job: Job) => {
});
}
// Save the PID to the database and a file for future management (stop/inspect)
const pid = subprocess.pid ?? null;
if (pid != null) {
await prisma.job.update({
where: { id: jobID },
data: { pid },
});
}
try {
fs.writeFileSync(path.join(trainingFolder, 'pid.txt'), String(pid ?? ''), { flag: 'w' });
} catch (e) {
console.error('Error writing pid file:', e);
}
// Important: let the child run independently of this Node process.
if (subprocess.unref) {
subprocess.unref();
}
// Optionally write a pid file for future management (stop/inspect) without keeping streams open
try {
fs.writeFileSync(path.join(trainingFolder, 'pid.txt'), String(subprocess.pid ?? ''), { flag: 'w' });
} catch (e) {
console.error('Error writing pid file:', e);
}
// (No stdout/stderr listeners — logging should go to --log handled by your Python)
// (No monitoring loop — the whole point is to let it live past this worker)
} catch (error: any) {