MCPcopy
hub / github.com/godaddy/terminus / run

Function run

example/express.cluster.js:19–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17const terminus = require('../lib/terminus').createTerminus
18
19function run () {
20 const app = express()
21 // Setup your express here
22 // Last in line, nothing else responded
23 app.use((req, res) => {
24 res.status(404).send('Sorry!')
25 })
26 const server = http.createServer(app)
27 const terminusOptions = {
28 useExit0: true,
29 beforeShutdown: () => {
30 // https://github.com/godaddy/terminus#how-to-set-terminus-up-with-kubernetes
31 const waitMS = 10_000 // default periodSeconds of livenessProbe
32 console.log('received SIGTERM')
33 console.log(`waiting ${waitMS} milliseconds for readinessCheck to fail`)
34 return new Promise(resolve => {
35 setTimeout(resolve, waitMS)
36 })
37 },
38 onSignal: () => {
39 console.log('starting cleanup')
40 return Promise.resolve()
41 },
42 onShutdown: () => {
43 console.log('BYE!')
44 return Promise.resolve()
45 }
46 }
47 terminus(server, terminusOptions)
48 server.listen(8080, () => {
49 console.log(`Express worker with PID: ${process.pid} started.`)
50 })
51}
52
53/**
54 * Shutdown the cluster workers properly

Callers 1

express.cluster.jsFile · 0.85

Calls 1

terminusFunction · 0.85

Tested by

no test coverage detected