From 5a60e4be70cd5ba12f138434a232896257fd8ecf Mon Sep 17 00:00:00 2001 From: TheEssem Date: Thu, 29 Apr 2021 18:55:58 -0500 Subject: [PATCH] hotfix moment --- api/index.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/api/index.js b/api/index.js index 12cf70f..b3f89bb 100644 --- a/api/index.js +++ b/api/index.js @@ -2,7 +2,9 @@ require("dotenv").config(); const os = require("os"); -const { run } = require("../utils/image-runner.js"); +//const { run } = require("../utils/image-runner.js"); +const { Worker } = require("worker_threads"); +const path = require("path"); const net = require("net"); const http = require("http"); @@ -184,7 +186,22 @@ const runJob = (job, sock) => { } log(`Job ${job.uuid} started`, job.num); - run(object).then((data) => { + const worker = new Worker(path.join(__dirname, "../utils/image-runner.js"), { + workerData: object + }); + worker.on("message", (data) => { + log(`Sending result of job ${job.uuid} back to the bot`, job.num); + const jobObject = jobs.get(job.uuid); + jobObject.data = data.buffer; + jobObject.ext = data.fileExtension; + jobs.set(job.uuid, jobObject); + sock.write(Buffer.concat([Buffer.from([0x1]), Buffer.from(job.uuid)]), (e) => { + if (e) return reject(e); + return resolve(); + }); + }); + worker.on("error", reject); + /*run(object).then((data) => { log(`Sending result of job ${job.uuid} back to the bot`, job.num); const jobObject = jobs.get(job.uuid); jobObject.data = data.buffer; @@ -194,9 +211,8 @@ const runJob = (job, sock) => { if (e) return reject(e); return resolve(); }); - return; }).catch(e => { reject(e); - }); + });*/ }); }; \ No newline at end of file