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