How to use the pm2.launchBus 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 gxchain / gxb-box / server / services / BoxService.js View on Github external
pm2.describe('gxb-box-pm2', function (err, processDescription) {
                if (err) {
                    reject(err);
                } else {
                    // 启动消息BUS,监听日志
                    if ((!is_started) && (processDescription && processDescription.length > 0)) {
                        let websocket = io.connect(url);

                        setInterval(function () {
                            pm2.describe('gxb-box-pm2', function (processDescription) {
                                websocket.emit('system', processDescription);
                            });
                        }, 1000);

                        pm2.launchBus(function (err, bus) {
                            if (err) return reject(err);
                            is_started = true;
                            bus.on('log:out', function (packet) {
                                websocket.emit('message', 'out', packet.data);
                            });
                            bus.on('log:err', function (packet) {
                                websocket.emit('message', 'err', packet.data);
                            });
                            return resolve(processDescription);
                        });
                    } else {
                        resolve(processDescription);
                    }
                }
            });
        });
github yasaricli / pmteor / imports / startup / server / polling.js View on Github external
restart_time,

                    // MONIT OBJECT INJECT
                    ...monit
                  }
                }
              });
            }));
          }
        }));
      }
    }));
  }), 10000); // 10 seconds.

  // Bus system - event monitoring
  pm2.launchBus(Meteor.bindEnvironment((err, bus) => {
    if (_.isNull(err)) {

      bus.on('*', Meteor.bindEnvironment((type, query) => {

        // EVENTS STOP, START, ...
        if (_.isEqual(type, 'process:event')) {
          let { PORT, name } = query.process;
          const application = Applications.findOne({ bundleId: name });

          if (application) {

            // CHANGE STATUS
            return Applications.update({ bundleId: name }, {
              $set: {
                status: STATUS_MAPPER[query.event.toUpperCase()],
                'env.PORT': PORT
github raychat / pm2-alert / index.js View on Github external
_launchBus(events) {
        const _this = this;
        pm2.launchBus(function (err, bus) {



            bus.on('process:event', packet => {
                if (events.indexOf(packet.event) != -1) {
                    console.log(packet)
                    let fields = [
                        {
                            "title": "Event",
                            "value": packet.event,
                            "short": false
                        },
                        {
                            "title": "Server",
                            "value": _this._config.info.serverName || 'UNKNOWN SERVER',
                            "short": false
github kuzzleio / kuzzle / lib / api / core / plugins / pluginsManager.js View on Github external
    .then(() => Promise.fromNode(callback => pm2.launchBus(callback)))
    .then(bus => {