might be a stupid idea

This commit is contained in:
TheEssem 2021-05-06 15:17:04 -05:00
parent c09142f7d3
commit 108afc3626

View file

@ -35,24 +35,23 @@ let jobAmount = 0;
const acceptJob = async (uuid, sock) => { const acceptJob = async (uuid, sock) => {
jobAmount++; jobAmount++;
queue.shift(); queue.shift();
try {
const job = jobs.get(uuid); const job = jobs.get(uuid);
await runJob({ runJob({
uuid: uuid, uuid: uuid,
msg: job.msg, msg: job.msg,
num: job.num num: job.num
}, sock); }, sock).then(() => {
log(`Job ${uuid} has finished`); log(`Job ${uuid} has finished`);
} catch (err) { }).catch((err) => {
console.error(`Error on job ${uuid}:`, err); console.error(`Error on job ${uuid}:`, err);
jobs.delete(uuid); jobs.delete(uuid);
sock.write(Buffer.concat([Buffer.from([0x2]), Buffer.from(uuid), Buffer.from(err.message)])); sock.write(Buffer.concat([Buffer.from([0x2]), Buffer.from(uuid), Buffer.from(err.message)]));
} finally { }).finally(() => {
jobAmount--; jobAmount--;
if (queue.length > 0) { if (queue.length > 0) {
acceptJob(queue[0], sock); acceptJob(queue[0], sock);
} }
} });
}; };
const httpServer = http.createServer((req, res) => { const httpServer = http.createServer((req, res) => {