diff --git a/bin/cli-serve b/bin/cli-serve index d40edc9e4..0a63aa6cf 100755 --- a/bin/cli-serve +++ b/bin/cli-serve @@ -1,8 +1,10 @@ #!/usr/bin/env node +const throng = require('throng'); +const { CONCURRENCY } = require('../config'); +const { logger } = require('../services/logging'); const util = require('./util'); const program = require('commander'); -const serve = require('../serve'); //============================================================================== // Setting up the program command line arguments. @@ -22,8 +24,18 @@ program ) .parse(process.argv); -// Start serving. -serve(program).catch(err => { - console.error(err); - util.shutdown(1); +throng({ + workers: CONCURRENCY, + start: i => { + logger.info({ workerID: i }, 'started worker'); + + // Load in the serve. + const serve = require('../serve'); + + // Start serving. + serve(program).catch(err => { + console.error(err); + util.shutdown(1); + }); + }, }); diff --git a/config.js b/config.js index 007aafb46..d01ad8817 100644 --- a/config.js +++ b/config.js @@ -217,6 +217,9 @@ const CONFIG = { // messages through the websocket to keep the socket alive. KEEP_ALIVE: process.env.TALK_KEEP_ALIVE || '30s', + // CONCURRENCY is the number of workers that will serve traffic. + CONCURRENCY: parseInt(process.env.TALK_CONCURRENCY || '1'), + //------------------------------------------------------------------------------ // Cache configuration //------------------------------------------------------------------------------ diff --git a/package.json b/package.json index 584afc428..75dcaf268 100644 --- a/package.json +++ b/package.json @@ -205,6 +205,7 @@ "style-loader": "^0.16.0", "subscriptions-transport-ws": "^0.7.2", "supports-color": "^4", + "throng": "^4.0.0", "timeago.js": "^2.0.3", "timekeeper": "^1.0.0", "tlds": "^1.196.0", diff --git a/services/kue.js b/services/kue.js index 380f6a8c5..9db766d0e 100644 --- a/services/kue.js +++ b/services/kue.js @@ -91,12 +91,12 @@ class Task { static shutdown() { debug('Shutting down the Queue'); - return new Promise((resolve, reject) => { + return new Promise(resolve => { // Shutdown and give the queue 5 seconds to shutdown before we start // killing jobs. getQueue().shutdown(5000, err => { if (err) { - return reject(err); + return resolve(); } debug('Queue shut down.'); diff --git a/yarn.lock b/yarn.lock index 8d904c9f7..e5f1afb14 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12823,6 +12823,13 @@ throat@^4.0.0: resolved "https://registry.yarnpkg.com/throat/-/throat-4.1.0.tgz#89037cbc92c56ab18926e6ba4cbb200e15672a6a" integrity sha1-iQN8vJLFarGJJua6TLsgDhVnKmo= +throng@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/throng/-/throng-4.0.0.tgz#983c6ba1993b58eae859998aa687ffe88df84c17" + integrity sha1-mDxroZk7WOroWZmKpof/6I34TBc= + dependencies: + lodash.defaults "^4.0.1" + through2@^2.0.0: version "2.0.3" resolved "https://registry.yarnpkg.com/through2/-/through2-2.0.3.tgz#0004569b37c7c74ba39c43f3ced78d1ad94140be"