might be a stupid idea
This commit is contained in:
parent
c09142f7d3
commit
108afc3626
1 changed files with 9 additions and 10 deletions
11
api/index.js
11
api/index.js
|
@ -35,24 +35,23 @@ let jobAmount = 0;
|
|||
const acceptJob = async (uuid, sock) => {
|
||||
jobAmount++;
|
||||
queue.shift();
|
||||
try {
|
||||
const job = jobs.get(uuid);
|
||||
await runJob({
|
||||
runJob({
|
||||
uuid: uuid,
|
||||
msg: job.msg,
|
||||
num: job.num
|
||||
}, sock);
|
||||
}, sock).then(() => {
|
||||
log(`Job ${uuid} has finished`);
|
||||
} catch (err) {
|
||||
}).catch((err) => {
|
||||
console.error(`Error on job ${uuid}:`, err);
|
||||
jobs.delete(uuid);
|
||||
sock.write(Buffer.concat([Buffer.from([0x2]), Buffer.from(uuid), Buffer.from(err.message)]));
|
||||
} finally {
|
||||
}).finally(() => {
|
||||
jobAmount--;
|
||||
if (queue.length > 0) {
|
||||
acceptJob(queue[0], sock);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const httpServer = http.createServer((req, res) => {
|
||||
|
|
Loading…
Reference in a new issue