Skip to content

Instantly share code, notes, and snippets.

@seye2
Last active August 6, 2020 09:48
Show Gist options
  • Save seye2/d433e0dc7b9056a447a9872e2e210824 to your computer and use it in GitHub Desktop.
Save seye2/d433e0dc7b9056a447a9872e2e210824 to your computer and use it in GitHub Desktop.
pm2
const pm2 = require('pm2');
module.exports = function pm2Emitter(file) {
if (!file || typeof file !== 'string') {
console.error('argument of type "string" required to run pm2Emitter');
return;
}
pm2.connect(function() {
pm2.list(function(err, processes) {
processes.forEach(function(process) {
console.log(`Sending message to process with pid: ${process.pm_id}`);
pm2.sendDataToProcessId(
{
type: 'process:msg',
data: {
file,
},
id: process.pm_id,
topic: 'bucket',
},
function(error) {
console.log(error);
console.log('message sent');
},
);
});
pm2.disconnect();
});
});
};
process.on('message', function(packet) {
process.send({
type : 'process:msg',
data : {
success : true
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment