2021-09-27 15:40:38 +00:00
|
|
|
const path = require("path");
|
|
|
|
const Bree = require("bree");
|
|
|
|
const { SHARE_ENV } = require("worker_threads");
|
2021-11-11 11:31:28 +00:00
|
|
|
const { log } = require("../src/util");
|
2021-09-27 15:40:38 +00:00
|
|
|
|
|
|
|
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
|
|
|
},
|
2021-09-27 15:40:38 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
const initBackgroundJobs = function (args) {
|
|
|
|
const bree = new Bree({
|
|
|
|
root: path.resolve("server", "jobs"),
|
|
|
|
jobs,
|
|
|
|
worker: {
|
|
|
|
env: SHARE_ENV,
|
|
|
|
workerData: args,
|
|
|
|
},
|
2021-10-09 15:33:47 +00:00
|
|
|
workerMessageHandler: (message) => {
|
2021-11-11 11:31:28 +00:00
|
|
|
log("jobs", message);
|
2021-10-09 15:33:47 +00:00
|
|
|
}
|
2021-09-27 15:40:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
bree.start();
|
|
|
|
return bree;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
initBackgroundJobs
|
|
|
|
};
|