Add heartbeat url for uptime monitoring
All checks were successful
NodBot Production Dockerization / build (pull_request) Successful in 19s
All checks were successful
NodBot Production Dockerization / build (pull_request) Successful in 19s
This commit is contained in:
parent
663c8e0a1a
commit
241679cc7f
13
functions.js
13
functions.js
@ -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));
|
||||
}
|
||||
};
|
||||
|
||||
|
9
main.js
9
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, 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
|
||||
|
Loading…
Reference in New Issue
Block a user