-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added base version of piscina run in ut
- Loading branch information
1 parent
c272267
commit db9cb2a
Showing
10 changed files
with
549 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
var Koa = require('koa'); | ||
var bodyParser = require('koa-bodyparser'); | ||
var cluster = require('./src/util/cluster'); | ||
var metricsRouter = require('./src/routes/metricsRouter').metricsRouter; | ||
var transformRoute = require('./src/routes/userTransformer'); | ||
const { transform } = require('lodash'); | ||
|
||
const app = new Koa(); | ||
|
||
const metricsApp = new Koa(); | ||
metricsApp.use(metricsRouter.routes()).use(metricsRouter.allowedMethods()); | ||
|
||
const clusterEnabled = process.env.CLUSTER_ENABLED !== 'false'; | ||
const port = parseInt(process.env.PORT ?? '9090', 10); | ||
|
||
app.use( | ||
bodyParser({ | ||
jsonLimit: '200mb', | ||
}), | ||
); | ||
|
||
app.use(transformRoute); | ||
|
||
if (clusterEnabled) { | ||
cluster.start(port, app, metricsApp); | ||
} else { | ||
// HTTP server for exposing metrics | ||
if (process.env.STATS_CLIENT === 'prometheus') { | ||
const metricsServer = metricsApp.listen(metricsPort); | ||
|
||
gracefulShutdown(metricsServer, { | ||
signals: 'SIGINT SIGTERM SIGSEGV', | ||
timeout: 30000, // timeout: 30 secs | ||
forceExit: false, // Don't force exit. Let graceful shutdown of server handle it. | ||
}); | ||
} | ||
|
||
const server = app.listen(port); | ||
|
||
process.on('SIGTERM', () => { | ||
console.error(`SIGTERM signal received`); | ||
}); | ||
|
||
process.on('SIGINT', () => { | ||
console.error(`SIGINT signal received`); | ||
}); | ||
|
||
process.on('SIGSEGV', () => { | ||
console.error(`SIGSEGV - JavaScript memory error occurred`); | ||
}); | ||
|
||
gracefulShutdown(server, { | ||
signals: 'SIGINT SIGTERM SIGSEGV', | ||
timeout: 30000, // timeout: 30 secs | ||
forceExit: true, // triggers process.exit() at the end of shutdown process | ||
finally: finalFunction, | ||
}); | ||
|
||
console.info(`App started. Listening on port: ${port}`); | ||
} | ||
|
||
module.exports = app; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.