Handle errors properly *and* also hopefully fix the file descriptor issue for real
This commit is contained in:
parent
ae32a3f9f1
commit
be53f8d352
1 changed files with 40 additions and 51 deletions
15
api/index.js
15
api/index.js
|
@ -64,14 +64,8 @@ if (isMainThread) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
worker.once("error", err => {
|
worker.once("error", err => {
|
||||||
console.error("worker error:", err);
|
console.error(`Error on worker ${uuid}:`, err);
|
||||||
socket.send(Buffer.concat([Buffer.from([0x2]), Buffer.from(uuid), Buffer.from(err.toString())]), jobs[uuid].port, jobs[uuid].addr);
|
socket.send(Buffer.concat([Buffer.from([0x2]), Buffer.from(uuid), Buffer.from(err.toString())]), jobs[uuid].port, jobs[uuid].addr);
|
||||||
|
|
||||||
workingWorkers--;
|
|
||||||
if (queue.length > 0) {
|
|
||||||
acceptJob(queue[0]);
|
|
||||||
delete jobs[uuid];
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
worker.once("exit", (code) => {
|
worker.once("exit", (code) => {
|
||||||
workingWorkers--;
|
workingWorkers--;
|
||||||
|
@ -80,7 +74,7 @@ if (isMainThread) {
|
||||||
delete jobs[uuid];
|
delete jobs[uuid];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code !== 0) console.error(`Worker stopped with exit code ${code}`);
|
if (code !== 0) console.error(`Worker ${uuid} stopped with exit code ${code}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -135,7 +129,6 @@ if (isMainThread) {
|
||||||
parentPort.once("message", async (job) => {
|
parentPort.once("message", async (job) => {
|
||||||
log(`${job.uuid} worker started`, job.threadNum);
|
log(`${job.uuid} worker started`, job.threadNum);
|
||||||
|
|
||||||
try {
|
|
||||||
const object = JSON.parse(job.msg);
|
const object = JSON.parse(job.msg);
|
||||||
let type;
|
let type;
|
||||||
if (object.path) {
|
if (object.path) {
|
||||||
|
@ -180,9 +173,5 @@ if (isMainThread) {
|
||||||
});
|
});
|
||||||
socket.send(Buffer.concat([Buffer.from([0x1]), Buffer.from(job.uuid), Buffer.from(job.port.toString())]), job.port, job.addr);
|
socket.send(Buffer.concat([Buffer.from([0x1]), Buffer.from(job.uuid), Buffer.from(job.port.toString())]), job.port, job.addr);
|
||||||
parentPort.postMessage(job.uuid); //Inform main thread about this worker freeing up
|
parentPort.postMessage(job.uuid); //Inform main thread about this worker freeing up
|
||||||
} catch (e) {
|
|
||||||
socket.send(Buffer.concat([Buffer.from([0x2]), Buffer.from(job.uuid), Buffer.from(e.toString())]), job.port, job.address);
|
|
||||||
parentPort.postMessage(job.uuid);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
Loading…
Reference in a new issue