From 149b3bb06dca488915d4f44ffaa25fc0cc30943f Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Mon, 22 May 2023 22:08:11 +0200 Subject: [PATCH] Renamed the healthchecks task -> integrations --- .../{healthchecks.js => integrations.js} | 33 +++++-------------- 1 file changed, 9 insertions(+), 24 deletions(-) rename server/tasks/{healthchecks.js => integrations.js} (50%) diff --git a/server/tasks/healthchecks.js b/server/tasks/integrations.js similarity index 50% rename from server/tasks/healthchecks.js rename to server/tasks/integrations.js index 1ac96c6b..8208e9bf 100644 --- a/server/tasks/healthchecks.js +++ b/server/tasks/integrations.js @@ -1,6 +1,5 @@ -const axios = require("axios"); -const config = require('../controller/config'); const schedule = require('node-schedule'); +const {triggerEvent} = require("../controller/integrations"); let currentState = "ping"; let job; @@ -10,27 +9,9 @@ module.exports.setState = (state = "ping") => { currentState = state; } -// Get the current health checks url from the config & format it -const getHealthChecksUrl = async () => { - let url = (await config.get("healthChecksUrl")).value.toString(); - if (url.includes("")) return null; - if (url.endsWith("/")) url = url.substring(0, url.length - 1); - - return url; -} - // Send a ping to the provided healthcheck server -module.exports.sendPing = async (path, message) => { - let url = await getHealthChecksUrl(); - if (url == null) return; - if (path) url += "/" + path; - - try { - const response = await axios.post(url, message, {headers: {"user-agent": "MySpeed/HealthAgent"}}); - if (response.data.includes("not found")) await config.resetDefault("healthChecksUrl"); - } catch (e) { - console.error("Could not send ping: " + e.message); - } +module.exports.sendPing = async (type, message) => { + await triggerEvent("minutePassed", {type, message}); } // Sends a ping only if the ping state is active @@ -40,12 +21,16 @@ module.exports.sendCurrent = async () => { // Sends an error to the healthcheck server module.exports.sendError = async (error = "Unknown error") => { - await this.sendPing("fail", error); + await triggerEvent("testFailed", error); } // Sends a 'running' ping to the healthcheck server module.exports.sendRunning = async () => { - await this.sendPing("start"); + await triggerEvent("testStarted"); +} + +module.exports.sendFinished = async (data) => { + await triggerEvent("testFinished", data); } // Starts a timer which sends a ping every minute