Skip to content

Instantly share code, notes, and snippets.

@tatethurston
Last active December 29, 2017 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tatethurston/99349a11ea7ecff7a00de76ce8d5964c to your computer and use it in GitHub Desktop.
Save tatethurston/99349a11ea7ecff7a00de76ce8d5964c to your computer and use it in GitHub Desktop.
node multiprocess
import * as throng from 'throng';
const { WEB_CONCURRENCY = 1, PORT = "" } = process.env;
const start = async (id: number) => {
/*
* This could be imported statically at the top, but then the master process
* could be crashed.
*/
const server = require('./server').default;
try {
await slackListener.start(PORT);
console.log(`Worker ${id} listening on port ${PORT}`);
} catch (e) {
console.error(e);
}
process.on('exit', () => {
console.log(`Worker ${id} exiting...`);
});
};
throng({
workers: WEB_CONCURRENCY,
start
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment