|
|
@ -2,12 +2,20 @@ const { parentPort, workerData } = require("worker_threads");
|
|
|
|
const Database = require("../database");
|
|
|
|
const Database = require("../database");
|
|
|
|
const path = require("path");
|
|
|
|
const path = require("path");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Send message to parent process
|
|
|
|
|
|
|
|
* @param {any} any The message to log
|
|
|
|
|
|
|
|
*/
|
|
|
|
const log = function (any) {
|
|
|
|
const log = function (any) {
|
|
|
|
if (parentPort) {
|
|
|
|
if (parentPort) {
|
|
|
|
parentPort.postMessage(any);
|
|
|
|
parentPort.postMessage(any);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Exit the worker process
|
|
|
|
|
|
|
|
* @param {number} error The status code to exit
|
|
|
|
|
|
|
|
*/
|
|
|
|
const exit = function (error) {
|
|
|
|
const exit = function (error) {
|
|
|
|
if (error && error != 0) {
|
|
|
|
if (error && error != 0) {
|
|
|
|
process.exit(error);
|
|
|
|
process.exit(error);
|
|
|
@ -20,6 +28,7 @@ const exit = function (error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Connects to the database */
|
|
|
|
const connectDb = async function () {
|
|
|
|
const connectDb = async function () {
|
|
|
|
const dbPath = path.join(
|
|
|
|
const dbPath = path.join(
|
|
|
|
process.env.DATA_DIR || workerData["data-dir"] || "./data/"
|
|
|
|
process.env.DATA_DIR || workerData["data-dir"] || "./data/"
|
|
|
|