From 80c8fd737226fcee13bfd165f8fae067d0b20811 Mon Sep 17 00:00:00 2001 From: Nelson Chan Date: Sat, 13 May 2023 01:51:23 +0800 Subject: [PATCH] Chore: Remove util-worker --- server/jobs/util-worker.js | 50 -------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 server/jobs/util-worker.js diff --git a/server/jobs/util-worker.js b/server/jobs/util-worker.js deleted file mode 100644 index 1aeec794..00000000 --- a/server/jobs/util-worker.js +++ /dev/null @@ -1,50 +0,0 @@ -const { parentPort, workerData } = require("worker_threads"); -const Database = require("../database"); -const path = require("path"); - -/** - * Send message to parent process for logging - * since worker_thread does not have access to stdout, this is used - * instead of console.log() - * @param {any} any The message to log - */ -const log = function (any) { - if (parentPort) { - parentPort.postMessage(any); - } -}; - -/** - * Exit the worker process - * @param {number} error The status code to exit - */ -const exit = function (error) { - if (error && error !== 0) { - process.exit(error); - } else { - if (parentPort) { - parentPort.postMessage("done"); - } else { - process.exit(0); - } - } -}; - -/** Connects to the database */ -const connectDb = async function () { - const dbPath = path.join( - process.env.DATA_DIR || workerData["data-dir"] || "./data/" - ); - - Database.init({ - "data-dir": dbPath, - }); - - await Database.connect(); -}; - -module.exports = { - log, - exit, - connectDb, -};