Some fixes

This commit is contained in:
Essem 2021-11-26 23:24:13 -06:00
parent 41068ae763
commit fe321e00b4
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
3 changed files with 11 additions and 9 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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;
}