Commit 360f771219bc4e27dad7098f686b4d3512a4b8fd

Authored by Adhidarma Hadiwinoto
1 parent 35895eb682
Exists in master and in 1 other branch dev

Cluster mode

Showing 1 changed file with 16 additions and 5 deletions Side-by-side Diff

... ... @@ -10,10 +10,21 @@ const config = require('komodo-sdk/config');
10 10 global.KOMODO_LOG_LABEL = `KOMODO-CENTER@${config.name || 'HTTPGETX'}`;
11 11 process.title = global.KOMODO_LOG_LABEL;
12 12  
13   -/*
14   -const matrix = require('komodo-sdk/matrix');
  13 +const cluster = require('cluster');
  14 +const logger = require('komodo-sdk/logger');
15 15  
16   -matrix.NODE_ENV = process.env.NODE_ENV;
17   -*/
  16 +if (config.cluster && cluster.isMaster) {
  17 + logger.info(`Running on cluster mode. Master ${process.pid} is running`);
18 18  
19   -require('./lib/listener-partner');
  19 + // eslint-disable-next-line no-plusplus
  20 + for (let i = 0; i < config.cluster; i++) {
  21 + cluster.fork();
  22 + }
  23 +} else {
  24 + if (config.cluster) {
  25 + logger.info(`Worker ${process.pid} started`);
  26 + }
  27 +
  28 + // eslint-disable-next-line global-require
  29 + require('./lib/listener-partner');
  30 +}