Fix the retrying not working.
This commit is contained in:
parent
5c7b1081ad
commit
84f6c26361
19
src/index.js
19
src/index.js
|
@ -45,20 +45,17 @@ if (rpm && rph) {
|
||||||
*/
|
*/
|
||||||
const history = {};
|
const history = {};
|
||||||
|
|
||||||
|
const getNow = () => Math.ceil(Date.now() / 1000); // Time in seconds
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} logs
|
* @param {string} logs
|
||||||
*/
|
*/
|
||||||
const pushHistory = (logs) => history[(new Date).getTime()] = logs;
|
const pushHistory = (logs) => history[getNow() + seconds] = logs;
|
||||||
|
|
||||||
const updateHistory = () => {
|
const updateHistory = () => {
|
||||||
const clearKeys = [];
|
const now = getNow();
|
||||||
|
const clearKeys = Object.keys(history)
|
||||||
const maxAge = (new Date).getTime() + seconds;
|
.filter((time) => time <= now);
|
||||||
for (const historyTime in history) {
|
|
||||||
if (historyTime > maxAge) {
|
|
||||||
clearKeys.push(historyTime)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
clearKeys.forEach((key) => delete history[key]);
|
clearKeys.forEach((key) => delete history[key]);
|
||||||
}
|
}
|
||||||
|
@ -101,7 +98,7 @@ const runCommand = () => {
|
||||||
console.error(`The process crashed more then ${historyMax} times in the past ${restartName}, stop retrying.`);
|
console.error(`The process crashed more then ${historyMax} times in the past ${restartName}, stop retrying.`);
|
||||||
console.error(`See below the past ${historyMax} crashes:`);
|
console.error(`See below the past ${historyMax} crashes:`);
|
||||||
for (const time in history) {
|
for (const time in history) {
|
||||||
console.error(`Crash @ ${time}:\n${history[time]}`);
|
console.error(`Crash @ ${time - seconds}:\n${history[time]}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,5 +110,5 @@ const runCommand = () => {
|
||||||
runner.stderr.on('data', (data) => handleOut('ERR', data.toString().trim()))
|
runner.stderr.on('data', (data) => handleOut('ERR', data.toString().trim()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command goes BRRRR
|
// Leggo!~
|
||||||
runCommand();
|
runCommand();
|
||||||
|
|
Loading…
Reference in New Issue