From 84c932d3f93d4ad1e64574716e7e4e615c0f4117 Mon Sep 17 00:00:00 2001 From: flifloo Date: Tue, 24 Nov 2020 01:09:20 +0100 Subject: [PATCH] Add agenda worker setup --- agenda/index.js | 18 ++++++++++++++++++ bin/www | 1 + 2 files changed, 19 insertions(+) create mode 100644 agenda/index.js 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); }