How to send messages from worker to parent? #187
Answered
by
titanism
omar-dulaimi
asked this question in
Q&A
-
Hello, I have been going through the examples in the repo, and there was something weird. I could not receive messages sent from inside a Bree Job. I can see in the logs that messages are getting sent, but in the file where I define Bree, I have a log statement there, that never gets executed! So, could you provide a very minimal working example on how to do that?
import { parentPort } from "worker_threads";
console.log("in worker!");
parentPort.postMessage("bye!")
const bree = new Bree({
doRootCheck: false,
root: false,
jobs: [
{
name: "main-job",
path: path.resolve(__dirname, "jobs", "main-job.js"),
interval: "2s",
},
],
});
if (parentPort) {
parentPort.on("message", (message) => {
console.log("message on bree: ", message);
});
}
await bree.start("main-job"); |
Beta Was this translation helpful? Give feedback.
Answered by
titanism
Jul 5, 2022
Replies: 1 comment
-
You need to use the option |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
titanism
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to use the option
workerMessageHandler
, see https://github.com/breejs/bree.