Add heartbeat url for uptime monitoring
This commit is contained in:
parent
dd313faa60
commit
e2658c41e5
10
main.js
10
main.js
@ -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, GatewayIntentBits, Partials, ActivityType } = require('discord.js');
|
||||
@ -43,6 +45,14 @@ client.once('ready', async () => {
|
||||
if (isDev == 'false') {
|
||||
statusChannel.send(`${new Date().toISOString()} -- \nStartup Sequence Complete <@481933290912350209>`);
|
||||
}
|
||||
|
||||
// Heartbeat Timer
|
||||
if (sendHeartbeat) {
|
||||
setInterval(() => {
|
||||
fn.sendHeartbeat(heartbeatUrl);
|
||||
}, 30000);
|
||||
if (isDev) console.log("Heartbeat interval set.");
|
||||
}
|
||||
});
|
||||
|
||||
// slash-commands
|
||||
|
@ -20,6 +20,7 @@ const slashCommandFiles = fs.readdirSync('./slash-commands/').filter(file => fil
|
||||
const dotCommandFiles = fs.readdirSync('./dot-commands/').filter(file => file.endsWith('.js'));
|
||||
const dbfn = require('./dbfn.js');
|
||||
const { finished } = require('stream');
|
||||
const https = require('https');
|
||||
|
||||
const functions = {
|
||||
// Functions for managing and creating Collections
|
||||
@ -1142,6 +1143,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));
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user