2020-12-12 18:08:49 +01:00
|
|
|
/*
|
|
|
|
SkeptIO | Gestionnaire des services
|
|
|
|
*/
|
|
|
|
|
|
|
|
const pm2 = require('pm2')
|
|
|
|
|
|
|
|
module.exports = (who) => {
|
|
|
|
|
|
|
|
function sendMSG(to, conf, data) {
|
|
|
|
if (!who) return console.error(`ERROR skeptIO ${to}`)
|
|
|
|
|
|
|
|
let dataMSG = {
|
|
|
|
topic: to,
|
|
|
|
from: 'skp_' + who,
|
|
|
|
conf,
|
|
|
|
data
|
|
|
|
}
|
|
|
|
|
|
|
|
pm2.list( (err, list) => { // on check la liste des process pm2
|
|
|
|
for (let i in list) {
|
|
|
|
if (list[i].name === 'skp_' + to) { // on verif que le process exite bien
|
|
|
|
pm2.sendDataToProcessId(list[i].pm_id, dataMSG, (err, res) => { // et on send
|
|
|
|
if (err) return console.error(` <-- [${list[i].pm_id}:${list[i].name}] error`, err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function receiveMSG(res) {
|
|
|
|
process.on('message', data => {
|
|
|
|
res(data)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
send: sendMSG,
|
|
|
|
receive: receiveMSG
|
|
|
|
}
|
|
|
|
}
|