Skip to content

Commit 77ea8a0

Browse files
[Penify]: Documentation for commit - b5926d5
1 parent d69b718 commit 77ea8a0

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

backend/server.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,16 @@ app.use(errorHandler);
302302
process.on('SIGTERM', gracefulShutdown);
303303
process.on('SIGINT', gracefulShutdown);
304304

305+
/**
306+
* Initiates a graceful shutdown of the server upon receiving a signal.
307+
*
308+
* The function logs the received signal and attempts to close the HTTP server.
309+
* It then proceeds to close database and Redis connections, logging each step.
310+
* If the shutdown process takes longer than 30 seconds, it forcefully exits the process.
311+
* In case of any errors during the shutdown, it logs the error and exits with a failure status.
312+
*
313+
* @param {string} signal - The signal that triggered the shutdown process.
314+
*/
305315
async function gracefulShutdown(signal) {
306316
logger.info(`Received ${signal}. Starting graceful shutdown...`);
307317

@@ -334,6 +344,9 @@ async function gracefulShutdown(signal) {
334344

335345
// === HELPER FUNCTIONS ===
336346

347+
/**
348+
* Retrieves the stages of the wheel, typically from a database.
349+
*/
337350
async function getWheelStages() {
338351
// This would typically come from database
339352
return [
@@ -350,21 +363,31 @@ async function getWheelStages() {
350363
];
351364
}
352365

366+
/**
367+
* Records the progress data for a user.
368+
*/
353369
async function recordProgress(progressData) {
354370
// This would save to database
355371
logger.info(`Recording progress for user ${progressData.userId}, stage ${progressData.stageId}`);
356372
return progressData;
357373
}
358374

375+
/** Encrypts insights using AES-GCM encryption. */
359376
async function encryptInsights(insights) {
360377
// This would use AES-GCM encryption
361378
return insights; // Placeholder
362379
}
363380

381+
/**
382+
* Closes database connections.
383+
*/
364384
async function closeDatabase() {
365385
// Close database connections
366386
}
367387

388+
/**
389+
* Closes Redis connections.
390+
*/
368391
async function closeRedis() {
369392
// Close Redis connections
370393
}

0 commit comments

Comments
 (0)