Closed MCSH closed 7 years ago
Hi My guess would be that it doesn't work with pm2 v2, only pm2 v1. Let me know if you are able to make the test work in your environment (in mine it does).
npm i
npm t
I will have a look to see if I can make pm2 v2 work.
I'm still able to run the tests successfully with pm2 v2.
None of the tests failed.
Still, I'm unable to run the examples provided in the Readme.md.
steps to reproduce:
npm init npm install pm2-bridge --save
sender.js:
const pm2Bridge = require('pm2-bridge');
pm2Bridge.send({
to: 'receiver', // send something to the process with the pm2 name 'receiver'
data: {message: 'ping'} // Send some data along
}).then(function(data) {
// Do something with the response
console.log(data.message); // pong
}, function(err) {
// Something went wrong :(
console.error(err)
});
receiver.js:
const pm2Bridge = require('pm2-bridge');
pm2Bridge.onMessage(function(data) {
// Do something with the data
// ...
console.log(data.from); // logs sender's pm2 name
console.log(data.data.message); // ping
// Reply when your done
this.reply({message: 'pong'});
});
pm2 kill # Just in case pm2 start sender.js receiver.js
I'm getting a timeout:
PM2 | Starting execution sequence in -fork mode- for app name:sender id:0
PM2 | App name:sender id:0 online
PM2 | Starting execution sequence in -fork mode- for app name:receiver id:1
PM2 | App name:receiver id:1 online
0|sender | Error: timeout exceeded
0|sender | at Timeout._onTimeout (/home/sajjad/tmp/pm2test/node_modules/pm2-br
idge/src/index.js:74:24)
0|sender | at ontimeout (timers.js:386:14)
0|sender | at tryOnTimeout (timers.js:250:5)
0|sender | at Timer.listOnTimeout (timers.js:214:5)
Your messages are not handled because you did not launch the process that handles all the messages. There is no convenient way yet to launch this process. You need to clone the pm2-bridge repository, do npm install
and launch the process with npm start
. Let me know if that works.
I will look into making this package available as a pm2 module so that it's much more convenient to launch and update.
I see. Thanks for letting me know.
It'd be great if you could make it into a pm2 module, much easier to work.
I'll close this issue and look for updates.
I've release a new version and updated the documentation.
Hi,
the example that you have provided doesn't work at all in the latest environment, any clue what might be wrong?
thanks in advance.