Last active
August 6, 2020 09:48
-
-
Save seye2/d433e0dc7b9056a447a9872e2e210824 to your computer and use it in GitHub Desktop.
pm2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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