This commit is contained in:
Nicolas 2024-08-23 22:33:17 -03:00
parent b9e06e27f4
commit d87b62fed9
2 changed files with 9 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import { Logger } from "../../lib/logger";
import { getScrapeQueue } from "../../services/queue-service";
import { checkAlerts } from "../../services/alerts";
import { exec } from "node:child_process";
import { sendSlackWebhook } from "../../services/alerts/slack";
export async function cleanBefore24hCompleteJobsController(
req: Request,
@ -140,6 +141,12 @@ export async function autoscalerController(req: Request, res: Response) {
if (targetMachineCount !== activeMachines) {
Logger.info(`🐂 Scaling from ${activeMachines} to ${targetMachineCount} - ${webScraperActive} active, ${webScraperWaiting} waiting`);
if(targetMachineCount > activeMachines) {
sendSlackWebhook("🐂 Scaling up to " + targetMachineCount + " machines", false, process.env.SLACK_AUTOSCALER ?? "");
} else {
sendSlackWebhook("🐂 Scaling down to " + targetMachineCount + " machines", false, process.env.SLACK_AUTOSCALER ?? "");
}
return res.status(200).json({
mode: "scale-descale",
count: targetMachineCount,

View File

@ -3,9 +3,9 @@ import { Logger } from "../../../src/lib/logger";
export async function sendSlackWebhook(
message: string,
alertEveryone: boolean = false
alertEveryone: boolean = false,
webhookUrl: string = process.env.SLACK_WEBHOOK_URL ?? ""
) {
const webhookUrl = process.env.SLACK_WEBHOOK_URL;
const messagePrefix = alertEveryone ? "<!channel> " : "";
const payload = {
text: `${messagePrefix} ${message}`,