Merge branch 'develop_v1.4.6'

This commit is contained in:
2023-11-01 16:49:35 +07:00
2 changed files with 40 additions and 24 deletions
+2
View File
@@ -15,6 +15,8 @@ RUNNING_ON_MULTIPLE_PORT=NO
# PISAHKAN DENGAN MENGGUNAKAN SEPARATOR KOMA TANPA SPASI # PISAHKAN DENGAN MENGGUNAKAN SEPARATOR KOMA TANPA SPASI
PORTS=3001,3002,3003,3004 PORTS=3001,3002,3003,3004
# ===================== CLUSTER NODE STICKY SESSION(YES or NO) ===========================
CLUSTER_NODE_STICKY_SESSION=YES
# =========================== KONFIGURASI UNTUK SERVER =========================== # =========================== KONFIGURASI UNTUK SERVER ===========================
# SERVER_FOR=development # SERVER_FOR=development
+38 -24
View File
@@ -5,7 +5,7 @@ const totalCPUs = require('node:os').cpus().length;
const process = require('node:process'); const process = require('node:process');
const winston = require('./application/helpers/winston.logger'); const winston = require('./application/helpers/winston.logger');
const app = require('./server'); const app = require('./server');
// const sticky = require('sticky-session'); const sticky = require('sticky-session');
var serverHSMStatus = 'HSM SERVER NOT CONNECTED'; var serverHSMStatus = 'HSM SERVER NOT CONNECTED';
if (process.env.NUMBER_SERVER_ACTIVE == '1') { if (process.env.NUMBER_SERVER_ACTIVE == '1') {
@@ -60,20 +60,6 @@ function startExpress() {
// set port, listen for requests // set port, listen for requests
const PORT = process.env.PORT || 3000; const PORT = process.env.PORT || 3000;
let message = `Server is running on version ${
process.env.VERSION
} environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `;
if (process.env.CLUSTER_NODE.toUpperCase() == 'YES') {
message = `Server is running with cluster node on version ${
process.env.VERSION
} environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `;
}
app.listen(PORT, () => {
winston.logger.info(message);
});
// jika settingan running on multiple // jika settingan running on multiple
if ( if (
process.env.RUNNING_ON_MULTIPLE_PORT.toUpperCase() == 'YES' && process.env.RUNNING_ON_MULTIPLE_PORT.toUpperCase() == 'YES' &&
@@ -107,18 +93,46 @@ function startExpress() {
winston.logger.warn( winston.logger.warn(
`If you want running the service on multiple port, please set CLUSTER_NODE = NO in .env file ` `If you want running the service on multiple port, please set CLUSTER_NODE = NO in .env file `
); );
} else if (
process.env.CLUSTER_NODE_STICKY_SESSION.toUpperCase() == 'YES' &&
process.env.CLUSTER_NODE.toUpperCase() == 'YES'
) {
winston.logger.warn(
`If you want running the service with sticky session, please set CLUSTER_NODE = NO in .env file `
);
} }
// const server = app.listen(PORT, () => { let message = `Server is running on version ${
// console.log( process.env.VERSION
// `Worker ${process.pid} started. Listening on port ${ } environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `;
// server.address().port
// }`
// );
// });
// // Use sticky-session with the server instance if (process.env.CLUSTER_NODE.toUpperCase() == 'YES') {
// sticky.listen(server); message = `Server is running with cluster node on version ${
process.env.VERSION
} environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `;
} else if (process.env.CLUSTER_NODE_STICKY_SESSION.toUpperCase() == 'YES') {
message = `Server is running with sticky session on version ${
process.env.VERSION
} environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `;
}
if (process.env.CLUSTER_NODE_STICKY_SESSION.toUpperCase() == 'YES') {
const server = app.listen(PORT, () => {
console.log(
`Worker ${process.pid} started. Listening on port ${
server.address().port
}`
);
winston.logger.info(message);
});
// Use sticky-session with the server instance
sticky.listen(server);
} else {
app.listen(PORT, () => {
winston.logger.info(message);
});
}
} }
// Use sticky-session to handle sticky sessions // Use sticky-session to handle sticky sessions