Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cluster support #4

Open
brandonros opened this issue Jul 17, 2018 · 1 comment
Open

cluster support #4

brandonros opened this issue Jul 17, 2018 · 1 comment

Comments

@brandonros
Copy link

var Promise = require('bluebird');
var micro = require('micro');
var fs = require('fs');

var os = require('os');
var cluster = require('cluster');

global.config = require(process.env.ENGINE_PATH + '/configs.js')[process.env.ENGINE_ENVIRONMENT];

var logger = require(process.env.ENGINE_PATH + '/lib/logger.js');
var router = require(process.env.ENGINE_PATH + '/lib/router.js');

var routes = require(process.env.ENGINE_PATH + '/routes/index.js');

var spawnThreads = function() {
  for (var i = 0; i < os.cpus().length; ++i) {
    var worker = cluster.fork();

    logger.log({level: 'info', message: `Spawned worker ${worker.id}...`});
  }
};

var bindServers = function() {
  var server = micro(router(routes));

  server.listen(global.config.port, function() {
    logger.log({level: 'info', message: 'Engine server listening...', port: global.config.port});
  });
};

(async function() {
  if (cluster.isMaster) {
    process.on('exit', function() {
      console.error('HERE');
      fs.unlinkSync(process.env.ENGINE_PATH + '/engine.pid');
    });

    spawnThreads();
  } else {
    bindServers();
  }
})();

The process.on('exit' never gets called from the master... do you have any advice on this?

@softsimon
Copy link

Anyone found a solution to this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants