sirian / node-cluster-hub Goto Github PK
View Code? Open in Web Editor NEWA layer for communcation between master and worker processes
License: MIT License
A layer for communcation between master and worker processes
License: MIT License
Why is async a dependency?
Because i don't see it being used anywhere in the code
Great module.
Could you please provide an example with more than one worker.
Thanks.
Hey. Here is an example Code:
const cluster = require('cluster');
const Hub = require('cluster-hub');
const hub = new Hub();
if (cluster.isMaster) {
var worker = cluster.fork();
hub.requestWorker(worker, 'myEvent', {
link: 'https://something'
}, (err, response) => {
if (err) return console.log(err);
console.log(response);
});
} else {
hub.on('myEvent', function (data, sender, callback) {
// callback(null, {success: true, body: '<html></html>'});
callback(new Error('TEST_ERROR'));
});
}
The err is always only
{}
Is this a problem with Nodejs or this Libary?
🚨 You need to enable Continuous Integration on all branches of this repository. 🚨
To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.
Since we didn’t receive a CI status on the greenkeeper/initial
branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.
If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/
.
Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial
branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.
This may be a misuse on my part but can you have two master hubs? I'm trying something like that and getting cross signals. This may be a cognitive fail on my part but is there a legitimate use case for two master hubs with different listeners, owning different workers, or are you always supposed to have a single hub per process and use application logic to discriminate?
The use case is I have two sets of processes; one collects text for a record, the other splits that text into keywords and maintains a count of keywords.
Hi,
I'm using hub and I got this error:
module.js:340
throw err;
^
Error: Cannot find module 'async'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (/var/www/dev/ui/msgsrv/node_modules/cluster-hub/lib/Hub.js:6:13)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
I manually installed async but it may be a good idea to include in the dependencies.
In the README, you initialize Hub by passing in the cluster module as the parameter. This sets this.messageKey
to whatever is exported from the cluster module. In my case, this causes a crash when sending messages because of the following error:
var string = JSON.stringify(message) + '\n';
^
TypeError: Converting circular structure to JSON
at Object.stringify (native)
at process.target._send (child_process.js:479:23)
at process.target.send (child_process.js:416:12)
at Worker.send (cluster.js:64:21)
at Hub.sendToMaster (/Users/danny/workspace/easerver/node_modules/cluster-hub/lib/Hub.js:128:24)
at Hub.doRequest (/Users/danny/workspace/easerver/node_modules/cluster-hub/lib/Hub.js:212:5)
at Hub.requestMaster (/Users/danny/workspace/easerver/node_modules/cluster-hub/lib/Hub.js:150:10)
The solution IMO is to pass a string or no parameter at all when initializing Hub(). I suggest updating the README to reflect this.
I'm currently trying to create a simple data storage on a master thread where worker threads would request the data as needed.
But I'm running into an issue where using the code below, I'm able to get the data just fine, I'm able to log it to console when referancing it inside the callback function. However outside the callback function the player variable is undefined despite having returned in the callback function.
Is there something I'm missing here?
export const getData = ( params: any, cback: Function): any => {
return clusterHub.requestMaster( 'getData', params, cback )
}
export const testDatastorage = () => {
setData( { store: "Players", idx: "testing", value: { steamID: "tested"} } )
let player = getData( { store: "Players", idx: "testing" }, ( err: Error, data: Player ): Player => {
console.log( "Inside the callback function", data )
return data
} )
console.log( "Outside the callback function", player )
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.