From 8572970882cc216ecc40a9e9d88f8687608aa022 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Sun, 28 Aug 2022 22:54:56 +0200 Subject: [PATCH] Implemented a scheduling system into the healthchecks task --- server/tasks/healthchecks.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/tasks/healthchecks.js b/server/tasks/healthchecks.js index f9630b55..30feddb7 100644 --- a/server/tasks/healthchecks.js +++ b/server/tasks/healthchecks.js @@ -1,7 +1,9 @@ const axios = require("axios"); const config = require('../controller/config'); +const schedule = require('node-schedule'); let currentState = "ping"; +let job; // Sets the current state (running = no pings, ping = send pings) module.exports.setState = (state = "ping") => { @@ -44,4 +46,9 @@ module.exports.sendError = async (error = "Unknown error") => { // Sends a 'running' ping to the healthcheck server module.exports.sendRunning = async () => { await this.sendPing("start"); +} + +// Starts a timer which sends a ping every minute +module.exports.startTimer = () => { + job = schedule.scheduleJob('* * * * *', () => this.sendCurrent()); } \ No newline at end of file