Last active
December 29, 2017 08:53
-
-
Save tatethurston/99349a11ea7ecff7a00de76ce8d5964c to your computer and use it in GitHub Desktop.
node multiprocess
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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