From afbfa709265708cc71a80c708ebdbfb52f136e58 Mon Sep 17 00:00:00 2001 From: ciniao <4041990@qq.com> Date: Thu, 14 Dec 2023 10:31:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E5=BC=80=E6=9C=8D=E5=A4=A9?= =?UTF-8?q?=E6=95=B0=EF=BC=8C=E8=AE=A1=E7=AE=97=E5=BC=80=E5=90=AF=E8=BF=9B?= =?UTF-8?q?=E7=A8=8B=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js_pm2.config.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/js_pm2.config.js b/js_pm2.config.js index af663c6..0efa009 100644 --- a/js_pm2.config.js +++ b/js_pm2.config.js @@ -29,6 +29,25 @@ if (env.SERVER_ID) { //读取服务配置 const config = fs.existsSync(path.resolve(__dirname, 'config.json')) ? JSON.parse(fs.readFileSync(path.resolve(__dirname, 'config.json'), 'utf-8')) : {}; const dis = config.serverId != undefined ? config.serverId : '0'; + + +let instancesNum = 8; +if(config.openTime){ + let openDate = new Date(config.openTime); + //计算openTime距离今天的天数 + let today = new Date(); + // 获取两个日期之间的毫秒差 + let timeDiff = today.getTime() - openDate.getTime(); + // 将毫秒差转换为天数 + let daysDiff = Math.floor(timeDiff / (1000 * 3600 * 24)); + console.log(`已开服天数:${daysDiff}`); + + //如果开服超过3天的区,则只开区2个进程 + if(daysDiff > 3){ + instancesNum = 2; + } +} + const localApps = [ { // 应用程序名称 @@ -38,7 +57,7 @@ const localApps = [ // 应用程序所在的目录 cwd: './', //集群实例数量,0表示根据cpu核心数自动控制 - instances: 8, + instances: instancesNum, // 传递给脚本的参数 args: '-serverType msg', // 是否启用监控模式,默认是false。如果设置成true,当应用程序变动时,pm2会自动重载。这里也可以设置你要监控的文件。