Add agenda worker setup
This commit is contained in:
parent
1ad5056ba7
commit
84c932d3f9
2 changed files with 19 additions and 0 deletions
18
agenda/index.js
Normal file
18
agenda/index.js
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
const { Worker } = require("worker_threads");
|
||||||
|
let nb = 0;
|
||||||
|
|
||||||
|
|
||||||
|
function startWorker(workerArgs) {
|
||||||
|
let worker = new Worker(...workerArgs);
|
||||||
|
worker.on("error", (err) => {
|
||||||
|
console.error(err);
|
||||||
|
nb--;
|
||||||
|
if (nb > 0)
|
||||||
|
startWorker(workerArgs);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = (app) => {
|
||||||
|
const workerArgs = ["./agenda/worker.js", {workerData: app.get("config")}];
|
||||||
|
startWorker(workerArgs);
|
||||||
|
};
|
1
bin/www
1
bin/www
|
@ -119,4 +119,5 @@ function onListening() {
|
||||||
? "pipe " + addr
|
? "pipe " + addr
|
||||||
: "port " + addr.port;
|
: "port " + addr.port;
|
||||||
debug("Listening on " + bind);
|
debug("Listening on " + bind);
|
||||||
|
require("../agenda")(app);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue