WIP: Enable background jobs

WIP: Remove better-sqlite3
This commit is contained in:
Nelson Chan
2021-09-27 23:40:38 +08:00
parent 6dd0e082b4
commit 656a4d6270
5 changed files with 570 additions and 6 deletions

28
server/jobs.js Normal file
View File

@@ -0,0 +1,28 @@
const path = require("path");
const Bree = require("bree");
const { SHARE_ENV } = require("worker_threads");
const jobs = [
{
name: "clear-old-data",
interval: "every 1 minute",
}
];
const initBackgroundJobs = function (args) {
const bree = new Bree({
root: path.resolve("server", "jobs"),
jobs,
worker: {
env: SHARE_ENV,
workerData: args,
},
});
bree.start();
return bree;
};
module.exports = {
initBackgroundJobs
};

View File

@@ -0,0 +1,24 @@
const path = require("path");
const { R } = require("redbean-node");
const Database = require("../database");
const dbPath = path.join(
process.env.DATA_DIR ||
require("worker_threads").workerData["data-dir"] ||
"./data/"
);
Database.init({
"data-dir": dbPath,
});
(async () => {
await Database.connect();
console.log(await R.getAll("PRAGMA journal_mode"));
console.log(
await R.getAll("SELECT * from setting WHERE key = 'database_version'")
);
process.exit(0);
})();

View File

@@ -46,6 +46,9 @@ Notification.init();
debug("Importing Database");
const Database = require("./database");
debug("Importing Background Jobs");
const { initBackgroundJobs } = require("./jobs");
const { basicAuth } = require("./auth");
const { login } = require("./auth");
const passwordHash = require("./password-hash");
@@ -1231,6 +1234,8 @@ exports.entryPage = "dashboard";
}
});
initBackgroundJobs(args);
})();
async function updateMonitorNotification(monitorID, notificationIDList) {