How to use the pm2.sendDataToProcessId function in pm2

To help you get started, we’ve selected a few pm2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github imsun / easy-pm / index.js View on Github external
return new Promise((resolve, reject) => {
		// There are some mistakes in PM2 API doc
		// Check:
		//   - https://github.com/Unitech/pm2/issues/2070
		//   - /node_modules/pm2/lib/God/ActionMethods.js `God.sendDataToProcessId`
		pm2.sendDataToProcessId(id, {
			id,
			data: {
				msg,
				id: msgId
			},
			type: 'process:msg',
			topic: 'stupid pm2'
		}, err => {
			if (err) return reject(err)
			__msgListeners[msgId] = resolve
		})
	})
}
github jeffallen6767 / chain / src / miner.js View on Github external
miningSlaves(function(miner) {
              var 
                // id of this miner
                pm_id = miner.pm2_env.pm_id;
              // don't tell the winning miner to stop-mining, it already has...
              if (id !== pm_id) {
                // send the stop-mining message to all the losers
                pm2.sendDataToProcessId(pm_id, {
                  topic: 'stop-mining',
                  // show the losers what a winning packet looks like, so they suffer a little more...
                  data: packet
                }, function(err, res) {
                  // check to see if the losers cry about it...
                  if (err) {
                    // TODO: maybe handle this better?
                    throw err;
                  }
                });
              }
            });
            // hand control back to the process that requested we mine...
github kuzzleio / kuzzle / lib / api / core / plugins / pluginsManager.js View on Github external
bus.on('ready', packet => {
        var pluginName = packet.process.name.replace(workerPrefix, '');
        console.log('pm2BusReady', packet);

        if (!pluginsWorker[pluginName] || !pluginsWorker[pluginName].config) {
          return false;
        }

        console.log('send init message',  {
          topic: 'initialize',
          data: {
            config: pluginsWorker[pluginName].config,
            path: pluginsWorker[pluginName].path
          }
        });
        pm2.sendDataToProcessId(packet.process.pm_id, {
          topic: 'initialize',
          data: {
            config: pluginsWorker[pluginName].config,
            path: pluginsWorker[pluginName].path,
            kuzzleConfig
          }
        }, (err) => {
          if (err) {
            console.error(`Error while sending data to plugin ${pluginName}: ${err}`);
          }
        });
      });
github vervallsweg / cast-web-api / manager.js View on Github external
return new Promise(resolve => {
            if (processDescription.pm2_env.status === 'online') {
                try {
                    pm2.sendDataToProcessId(processDescription.pm_id, {
                        type : 'process:msg',
                        data : {
                            some : 'data',
                            hello : true
                        },
                        topic: 'some topic'
                    }, function(err, res) {
                        if (err) {
                            console.error(err);
                            resolve(false);
                        }
                    });
                } catch (e) {
                    console.error(e);
                    resolve(false);
                }
github kuzzleio / kuzzle / lib / api / core / plugins / pluginsManager.js View on Github external
async.forEachOf(this.workers, (worker, workerName, callback) => {
      var pmId;

      if (worker.events.indexOf(event) === -1 && worker.events.indexOf(wildcardEvent) === -1) {
        return callback();
      }

      pmId = worker.pmIds.getNext();
      pm2.sendDataToProcessId(pmId, {
        topic: 'trigger',
        data: {
          event: event,
          message: data
        },
        id: pmId
      }, (err, res) => {
        callback(err, res);
      });
    }, (err) => {
      if (err) {
github remux-io / remuxme / lib / remuxme-pm2.js View on Github external
pm2.list(function(err, pm2_apps){
        if (err) {
          callback(err, procs)
        }

        var app = pm2_apps.find(function(item){if(item.name=='remux_ffmpeg_'+proc.name) return true})

        if (app){
          pm2.sendDataToProcessId(app.pm_id, {
            data : {
              'cmd':'taskset',
              'args':cpus
            },
            type : 'process:msg',
            topic: 'topic',
            id   : app.pm_id
          },
          function (err, res){
            callback(err, res)
          })

        }else{
          callback(`Process with id ${id} not started.`, null)
        }
      })
github adobe / athena / src / cluster / commands.js View on Github external
pm2.list(function(err, list) {
    pm2.sendDataToProcessId(
        list[0].pm2_env.pm_id,
        makeMessage(messageType, {data}),
        _handleError
    );
  });