2021-09-27 08:40:38 -07:00
|
|
|
const path = require("path");
|
|
|
|
const Bree = require("bree");
|
|
|
|
const { SHARE_ENV } = require("worker_threads");
|
|
|
|
|
|
|
|
const jobs = [
|
|
|
|
{
|
|
|
|
name: "clear-old-data",
|
2021-10-09 08:33:47 -07:00
|
|
|
interval: "every 1 day",
|
2021-09-27 08:40:38 -07:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
const initBackgroundJobs = function (args) {
|
|
|
|
const bree = new Bree({
|
|
|
|
root: path.resolve("server", "jobs"),
|
|
|
|
jobs,
|
|
|
|
worker: {
|
|
|
|
env: SHARE_ENV,
|
|
|
|
workerData: args,
|
|
|
|
},
|
2021-10-09 08:33:47 -07:00
|
|
|
workerMessageHandler: (message) => {
|
|
|
|
console.log("[Background Job]:", message);
|
|
|
|
}
|
2021-09-27 08:40:38 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
bree.start();
|
|
|
|
return bree;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
initBackgroundJobs
|
|
|
|
};
|