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) => {
|
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) => {
|
||||||
|
|
Loading…
Reference in a new issue