Another attempt to fix the EMFILE error, update license for the new year

This commit is contained in:
TheEssem 2021-01-02 22:40:44 -06:00
parent 67ca7d79d0
commit 87ab7d39d4
2 changed files with 9 additions and 7 deletions

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2020 Essem Copyright (c) 2021 Essem
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -1,4 +1,4 @@
// code provided by tzlil // code originally provided by tzlil
require("dotenv").config(); require("dotenv").config();
const os = require("os"); const os = require("os");
@ -91,7 +91,6 @@ if (isMainThread) {
port: jobs[uuid].port, port: jobs[uuid].port,
threadNum: workingWorkers threadNum: workingWorkers
}); });
return;
}; };
const server = dgram.createSocket("udp4"); //Create a UDP server for listening to requests, we dont need tcp 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); queue.push(uuid);
if (workingWorkers < MAX_WORKERS) { if (workingWorkers < MAX_WORKERS) {
log(`Got request for job ${job.msg} with id ${uuid}`, job.threadNum);
acceptJob(uuid); 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)]); 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 !!! server.bind(8080); // ATTENTION: Always going to be bound to 0.0.0.0 !!!
} else { } else {
parentPort.once("message", async (job) => { parentPort.once("message", async (job) => {
log(`${job.uuid} worker got: ${job.msg}`, job.threadNum); log(`${job.uuid} worker started`, job.threadNum);
try { try {
const object = JSON.parse(job.msg); const object = JSON.parse(job.msg);
@ -157,10 +159,10 @@ if (isMainThread) {
const data = await magick.run(object, true); const data = await magick.run(object, true);
log(`${job.uuid} is done`, job.threadNum); log(`${job.uuid} is done`, job.threadNum);
const server = net.createServer(function(socket) { const server = net.createServer(function(tcpSocket) {
socket.write(Buffer.concat([Buffer.from(type ? type : "image/png"), Buffer.from("\n"), data]), (err) => { tcpSocket.write(Buffer.concat([Buffer.from(type ? type : "image/png"), Buffer.from("\n"), data]), (err) => {
if (err) console.error(err); if (err) console.error(err);
socket.end(() => { tcpSocket.end(() => {
process.exit(); process.exit();
}); });
}); });