From fe321e00b49977cd4154338d5e4e6bbdc06edf03 Mon Sep 17 00:00:00 2001 From: Essem Date: Fri, 26 Nov 2021 23:24:13 -0600 Subject: [PATCH] Some fixes --- api/index.js | 9 ++++----- commands/general/imagestats.js | 2 +- utils/imageConnection.js | 9 ++++++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/api/index.js b/api/index.js index 32a7869..8602063 100644 --- a/api/index.js +++ b/api/index.js @@ -86,11 +86,10 @@ const wss = new WebSocketServer({ clientTracking: true, noServer: true }); wss.on("connection", (ws, request) => { log(`WS client ${request.socket.remoteAddress}:${request.socket.remotePort} has connected`); - - ws.on("open", () => { - const init = Buffer.concat([Buffer.from([Rinit]), Buffer.from(MAX_JOBS), Buffer.from(JSON.stringify(Object.keys(magick)))]); - ws.send(init); - }); + const num = Buffer.alloc(2); + num.writeUInt16LE(MAX_JOBS); + const init = Buffer.concat([Buffer.from([Rinit]), num, Buffer.from(JSON.stringify(Object.keys(magick)))]); + ws.send(init); ws.on("error", (err) => { console.error(err); diff --git a/commands/general/imagestats.js b/commands/general/imagestats.js index eace592..d2cbd32 100644 --- a/commands/general/imagestats.js +++ b/commands/general/imagestats.js @@ -18,7 +18,7 @@ class ImageStatsCommand extends Command { for (let i = 0; i < servers.length; i++) { embed.embeds[0].fields.push({ name: `Server ${i + 1}`, - value: `Running Jobs: ${servers[i].runningJobs}\nQueued: ${servers[i].queued}\nMax Jobs: ${servers[i].max}` + value: `Running Jobs: ${servers[i].runningJobs}\nQueued: ${Math.max(0, servers[i].runningJobs - servers[i].max)}\nMax Jobs: ${servers[i].max}` }); } return embed; diff --git a/utils/imageConnection.js b/utils/imageConnection.js index 4181625..04e3e4c 100644 --- a/utils/imageConnection.js +++ b/utils/imageConnection.js @@ -15,11 +15,11 @@ Rinit 0x08 */ const Rerror = 0x01; const Tqueue = 0x02; -//const Rqueue = 0x03; +const Rqueue = 0x03; const Tcancel = 0x04; -//const Rcancel = 0x05; +const Rcancel = 0x05; const Twait = 0x06; -//const Rwait = 0x07; +const Rwait = 0x07; const Rinit = 0x08; class ImageConnection { @@ -66,7 +66,10 @@ class ImageConnection { const tag = msg.readUint32LE(1); const promise = this.requests.get(tag); this.requests.delete(tag); + if (op === Rqueue) this.njobs++; + if (op === Rcancel || op === Rwait) this.njobs--; if (op === Rerror) { + this.njobs--; promise.reject(new Error(msg.slice(5, msg.length).toString())); return; }