setInterval only if in pm2

This commit is contained in:
Jack Liao 2020-07-07 19:09:14 +08:00
parent 87eadcc9fa
commit 9e85cfaaec
1 changed files with 11 additions and 4 deletions

View File

@ -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