diff --git a/LICENSE b/LICENSE index 1785ced..b215673 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Essem +Copyright (c) 2021 Essem Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/api/index.js b/api/index.js index c49b701..396bee6 100644 --- a/api/index.js +++ b/api/index.js @@ -1,4 +1,4 @@ -// code provided by tzlil +// code originally provided by tzlil require("dotenv").config(); const os = require("os"); @@ -91,7 +91,6 @@ if (isMainThread) { port: jobs[uuid].port, threadNum: workingWorkers }); - return; }; const server = dgram.createSocket("udp4"); //Create a UDP server for listening to requests, we dont need tcp @@ -111,7 +110,10 @@ if (isMainThread) { queue.push(uuid); if (workingWorkers < MAX_WORKERS) { + log(`Got request for job ${job.msg} with id ${uuid}`, job.threadNum); acceptJob(uuid); + } else { + log(`Got request for job ${job.msg} with id ${uuid}, queued in position ${queue.indexOf(uuid) - 1}`, job.threadNum); } const newBuffer = Buffer.concat([Buffer.from([0x0]), Buffer.from(uuid)]); @@ -131,7 +133,7 @@ if (isMainThread) { server.bind(8080); // ATTENTION: Always going to be bound to 0.0.0.0 !!! } else { parentPort.once("message", async (job) => { - log(`${job.uuid} worker got: ${job.msg}`, job.threadNum); + log(`${job.uuid} worker started`, job.threadNum); try { const object = JSON.parse(job.msg); @@ -157,10 +159,10 @@ if (isMainThread) { const data = await magick.run(object, true); log(`${job.uuid} is done`, job.threadNum); - const server = net.createServer(function(socket) { - socket.write(Buffer.concat([Buffer.from(type ? type : "image/png"), Buffer.from("\n"), data]), (err) => { + const server = net.createServer(function(tcpSocket) { + tcpSocket.write(Buffer.concat([Buffer.from(type ? type : "image/png"), Buffer.from("\n"), data]), (err) => { if (err) console.error(err); - socket.end(() => { + tcpSocket.end(() => { process.exit(); }); });