Reputation: 934
I need to pass command-line arguments or params or execargv which should come in process params while loading environment for a child process which will be launched by a bull for process a job.
is it possible? if yes is there any way to do it?
I can identify the child process is launched for bull usings args[1] which contains /bull/lib/process but I want to pass custom param to node process.
Upvotes: 0
Views: 731
Reputation: 3024
when a worker script runs, it reads the environment and keeps it until you shut it down.
If you need variable parameters to the function the worker should use, then it is best you send them in your queue.
queue.js
queue.add("foo", {params:"parameters you need", payload:{ foo: "bar" }});
worker.js
const worker = new Worker("foo",
async (job) => {
await your_function(job.data.params, job.data.payload);
}
);
const your_function = async (params, payload) => {
require("fs").writeFileSync("runner.json", JSON.stringify(payload), "utf8");
await require("child_process").fork("runner.js", params.split(" "));
};
runner.js
console.log(process.argv);
const fs = require("fs");
fs.readFile("runner.json", "utf8", function (err, data) {console.log("data: ", JSON.parse(data));});
Upvotes: 0