From 92aa2575200e377158bbb3d8bf11fcb55a49e65b Mon Sep 17 00:00:00 2001 From: Wizzard Date: Mon, 17 Jul 2023 10:29:07 -0700 Subject: [PATCH] Additional logging and auto restart every 6 hours --- main.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 413e021..0c4ae7c 100644 --- a/main.js +++ b/main.js @@ -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; } -} +} \ No newline at end of file