diff --git a/agenda/index.js b/agenda/index.js new file mode 100644 index 0000000..813cb12 --- /dev/null +++ b/agenda/index.js @@ -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); +}; diff --git a/bin/www b/bin/www index e8cd115..0e0c83c 100755 --- a/bin/www +++ b/bin/www @@ -119,4 +119,5 @@ function onListening() { ? "pipe " + addr : "port " + addr.port; debug("Listening on " + bind); + require("../agenda")(app); }