uptime-kuma/server/jobs.js
Louis Lam 279e2eb3f6 Merge branch 'master' into logging
# Conflicts:
#	server/database.js
#	server/jobs.js
#	server/model/monitor.js
#	server/routers/api-router.js
#	server/server.js
#	server/socket-handlers/status-page-socket-handler.js
#	server/util-server.js
2022-04-12 16:32:14 +08:00

39 lines
771 B
JavaScript

const path = require("path");
const Bree = require("bree");
const { SHARE_ENV } = require("worker_threads");
const { log_info } = require("../src/util");
let bree;
const jobs = [
{
name: "clear-old-data",
interval: "at 03:14",
},
];
const initBackgroundJobs = function (args) {
bree = new Bree({
root: path.resolve("server", "jobs"),
jobs,
worker: {
env: SHARE_ENV,
workerData: args,
},
workerMessageHandler: (message) => {
log_info("jobs", message);
}
});
bree.start();
return bree;
};
const stopBackgroundJobs = function () {
if (bree) {
bree.stop();
}
};
module.exports = {
initBackgroundJobs,
stopBackgroundJobs
};