From 84f6c26361097c955afa1c16fe4d7c0d88115fca Mon Sep 17 00:00:00 2001 From: Ian Wijma Date: Sun, 19 Nov 2023 14:21:54 +1100 Subject: [PATCH] Fix the retrying not working. --- src/index.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/index.js b/src/index.js index a646fc3..63a3181 100644 --- a/src/index.js +++ b/src/index.js @@ -45,20 +45,17 @@ if (rpm && rph) { */ const history = {}; +const getNow = () => Math.ceil(Date.now() / 1000); // Time in seconds + /** * @param {string} logs */ -const pushHistory = (logs) => history[(new Date).getTime()] = logs; +const pushHistory = (logs) => history[getNow() + seconds] = logs; const updateHistory = () => { - const clearKeys = []; - - const maxAge = (new Date).getTime() + seconds; - for (const historyTime in history) { - if (historyTime > maxAge) { - clearKeys.push(historyTime) - } - } + const now = getNow(); + const clearKeys = Object.keys(history) + .filter((time) => time <= now); 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(`See below the past ${historyMax} crashes:`); 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())) } -// Command goes BRRRR +// Leggo!~ runCommand();