Additional logging and auto restart every 6 hours

This commit is contained in:
Wizzard 2023-07-17 10:29:07 -07:00
parent 2926d0e468
commit 92aa257520
1 changed files with 11 additions and 2 deletions

13
main.js
View File

@ -7,8 +7,10 @@ const config = JSON.parse(fs.readFileSync("config.json"));
const updateInterval = 5000;
const retryInterval = 30000;
const maxUptime = 6 * 60 * 60 * 1000; // Maximum uptime before restart (6 hours)
let rp;
let startTime = Date.now();
function formatNumber(number) {
var x = number.split(".");
@ -68,7 +70,14 @@ async function updateStatus() {
],
});
console.log("Discord status updated.");
console.log("Discord status updated. Current track: " + data.trackName + ", Artist: " + data.artist);
// check if uptime exceeds maximum uptime
if ((Date.now() - startTime) > maxUptime) {
console.log("Max uptime reached, restarting process...");
process.exit(0);
}
setTimeout(updateStatus, updateInterval);
} catch (error) {
console.error("Failed to update status:", error);
@ -144,4 +153,4 @@ async function fetchCurrentScrobble(user) {
console.error("Failed to fetch current scrobble for track: " + lastTrackName + " by artist: " + lastArtist, error);
return null;
}
}
}