uptime-kuma/server/jobs.js

39 lines
742 B
JavaScript
Raw Normal View History

const path = require("path");
const Bree = require("bree");
const { SHARE_ENV } = require("worker_threads");
let bree;
const jobs = [
{
name: "clear-old-data",
2021-10-09 16:16:29 +00:00
interval: "at 03:14",
2021-10-23 13:44:21 +00:00
},
];
const initBackgroundJobs = function (args) {
bree = new Bree({
root: path.resolve("server", "jobs"),
jobs,
worker: {
env: SHARE_ENV,
workerData: args,
},
workerMessageHandler: (message) => {
console.log("[Background Job]:", message);
}
});
bree.start();
return bree;
};
const stopBackgroundJobs = function () {
if (bree) {
bree.stop();
}
};
module.exports = {
initBackgroundJobs,
stopBackgroundJobs
};