Skip to content

Commit

Permalink
feat: added base version of piscina run in ut
Browse files Browse the repository at this point in the history
  • Loading branch information
abhimanyubabbar committed Feb 19, 2025
1 parent c272267 commit db9cb2a
Show file tree
Hide file tree
Showing 10 changed files with 549 additions and 2 deletions.
62 changes: 62 additions & 0 deletions index.js
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;
298 changes: 298 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"oauth-1.0a": "^2.2.6",
"object-hash": "^3.0.0",
"parse-static-imports": "^1.1.0",
"piscina": "^4.3.0",
"prom-client": "^14.2.0",
"qs": "^6.11.1",
"rs-jsonpath": "^1.1.2",
Expand Down
Loading

0 comments on commit db9cb2a

Please sign in to comment.