From 9e85cfaaec2d12848fed03e4c2e8ab2d11f99324 Mon Sep 17 00:00:00 2001 From: Jack Liao Date: Tue, 7 Jul 2020 19:09:14 +0800 Subject: [PATCH] setInterval only if in pm2 --- src/gd.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/gd.js b/src/gd.js index e1d3c21..6ab3e04 100644 --- a/src/gd.js +++ b/src/gd.js @@ -22,10 +22,17 @@ const SA_FILES = fs.readdirSync(path.join(__dirname, SA_PATH)).filter(v => v.end SA_FILES.flag = 0 let SA_TOKENS = get_sa_batch() -setInterval(() => { - SA_FILES.flag = 0 - SA_TOKENS = get_sa_batch() -}, 1000 * 3600 * 12) +if (is_pm2()) { + setInterval(() => { + SA_FILES.flag = 0 + SA_TOKENS = get_sa_batch() + }, 1000 * 3600 * 12) +} + +// https://github.com/Leelow/is-pm2/blob/master/index.js +function is_pm2 () { + return 'PM2_HOME' in process.env || 'PM2_JSON_PROCESSING' in process.env || 'PM2_CLI' in process.env +} function get_sa_batch () { const new_flag = SA_FILES.flag + SA_BATCH_SIZE