mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-10 07:34:07 -08:00
40 lines
764 B
JavaScript
40 lines
764 B
JavaScript
|
const { parentPort, workerData } = require("worker_threads");
|
||
|
const Database = require("../database");
|
||
|
const path = require("path");
|
||
|
|
||
|
const log = function (any) {
|
||
|
if (parentPort) {
|
||
|
parentPort.postMessage(any);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const exit = function (error) {
|
||
|
if (error && error != 0) {
|
||
|
process.exit(error);
|
||
|
} else {
|
||
|
if (parentPort) {
|
||
|
parentPort.postMessage("done");
|
||
|
} else {
|
||
|
process.exit(0);
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
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,
|
||
|
};
|