diff --git a/services/healthchecks.ts b/services/healthchecks.ts new file mode 100644 index 00000000..c47f5b43 --- /dev/null +++ b/services/healthchecks.ts @@ -0,0 +1,14 @@ +import axios from "axios"; +import macros from "../utils/macros"; + +export async function sendHealthCheck(): Promise { + /** + * Sends out a ping to the pingURL, if there is an error with the updater, + * a message will be sent to the Search-Support channel in the sandbox slack. + */ + try { + await axios.get(process.env.HEALTHCHECK_PING); + } catch (error) { + macros.warn("Health checks service is not responding properly: " + error); + } +} diff --git a/services/updater.ts b/services/updater.ts index 4352c98f..ffb3fd46 100644 --- a/services/updater.ts +++ b/services/updater.ts @@ -21,6 +21,7 @@ import { } from "../types/scraperTypes"; import processor from "../scrapers/classes/main"; import filters from "../scrapers/filters"; +import { sendHealthCheck } from "./healthchecks"; /* At most, there are 12 terms that we want to update - if we're in the spring & summer semesters have been posted @@ -362,6 +363,10 @@ class Updater { await this.sendUserNotifications(sections); // Save the data in our database await this.saveDataToDatabase(sections); + // Send out healthcheck ping in prod + if (macros.PROD) { + await sendHealthCheck(); + } const totalTime = Date.now() - startTime; macros.log( diff --git a/template.env b/template.env index 368b4869..c5b09966 100644 --- a/template.env +++ b/template.env @@ -9,4 +9,7 @@ CLIENT_ORIGIN=http://localhost:5000 JWT_SECRET= # This is only used for local development -POSTGRES_PASSWORD=default_password \ No newline at end of file +POSTGRES_PASSWORD=default_password + +# Healtchecks ping server +HEALTHCHECK_PING = https://hc-ping.com/7d9197be-db67-4cc5-be00-1a3df56d0918 \ No newline at end of file