From bd737acaa2e324fe1a857d94327abb4aa2197e65 Mon Sep 17 00:00:00 2001 From: Ben Allfree Date: Tue, 23 Jan 2024 12:13:50 +0000 Subject: [PATCH] update: health check --- src/cli/edge-health.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/cli/edge-health.ts b/src/cli/edge-health.ts index 29bbda16..b4df7f8f 100644 --- a/src/cli/edge-health.ts +++ b/src/cli/edge-health.ts @@ -7,6 +7,7 @@ import { SETTINGS, } from '$constants' import { LoggerService, LogLevelName } from '$shared' +import Bottleneck from 'bottleneck' import { execSync } from 'child_process' import fetch from 'node-fetch' import { freemem } from 'os' @@ -172,9 +173,9 @@ const content = [ if (isInstance) { return `${ isHealthy ? ':white_check_mark:' : ':face_vomiting: ' - } ${emoji} \`${name.padStart(20)} ${(mem || '').padStart(10)} ${ + } ${emoji} \`${name.padStart(30)} ${(mem || '').padStart(10)} ${( ago || '' - }\`` + ).padStart(20)}\`` } return `${ isHealthy ? ':white_check_mark:' : ':face_vomiting: ' @@ -205,14 +206,17 @@ function splitIntoChunks(lines: string[], maxChars: number = 2000): string[] { dbg(content) +const limiter = new Bottleneck({ maxConcurrent: 1 }) await Promise.all( - splitIntoChunks(content).map(async (content) => { - await fetch(DISCORD_URL, { - method: 'POST', - body: JSON.stringify({ - content, + splitIntoChunks(content).map((content) => + limiter.schedule(() => + fetch(DISCORD_URL, { + method: 'POST', + body: JSON.stringify({ + content, + }), + headers: { 'content-type': 'application/json' }, }), - headers: { 'content-type': 'application/json' }, - }) - }), + ), + ), )