Add heartbeat url for uptime monitoring
All checks were successful
NodBot Production Dockerization / build (pull_request) Successful in 19s

This commit is contained in:
Skylar Grant 2023-08-10 22:12:14 -04:00
parent 663c8e0a1a
commit 241679cc7f
2 changed files with 22 additions and 0 deletions

View File

@ -670,6 +670,19 @@ const functions = {
}
const errorId = digits.join("");
return errorId;
},
async sendHeartbeat(url) {
console.log(url);
https.get(url, async (response) => {
let data = '';
response.on('data', (chunk) => data += chunk);
response.on('end', () => {
parsedData = JSON.parse(data);
if ( !(parsedData.ok) ) console.error("Heartbeat failed");
});
}).on("error", (error) => console.error(error));
}
};

View File

@ -5,6 +5,8 @@ const dotenv = require('dotenv');
dotenv.config();
const token = process.env.TOKEN;
const statusChannelId = process.env.statusChannelId;
const heartbeatUrl = process.env.HEARTBEAT_URL;
const sendHeartbeat = typeof heartbeatUrl === 'string';
// Discord.JS
const { Client, Intents } = require('discord.js');
@ -44,6 +46,13 @@ client.once('ready', async () => {
await client.channels.fetch(statusChannelId).then(channel => {
channel.send(`${new Date().toISOString()} -- <@${process.env.ownerId}>\nStartup Sequence Complete`);
});
// Heartbeat Timer
if (sendHeartbeat) {
setInterval(() => {
fn.sendHeartbeat(heartbeatUrl);
}, 30000);
if (isDev) console.log("Heartbeat interval set.");
}
});
// slash-commands