From c699cb3c47051bd9e05c33ee98ecf4f1e065e6a7 Mon Sep 17 00:00:00 2001 From: if1live Date: Tue, 3 Oct 2023 03:53:35 +0900 Subject: [PATCH] =?UTF-8?q?=EB=A1=9C=EA=B7=B8=20=EC=B6=9C=EB=A0=A5=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services.ts | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/src/services.ts b/src/services.ts index 3bdbb17..eae38ff 100644 --- a/src/services.ts +++ b/src/services.ts @@ -10,9 +10,10 @@ import { PostgresInput, ProviderInput, RedisNativeInput, + TouchRejectedResult, UpstashRedisInput, } from "./types.js"; -import { providerInputs, DISCORD_WEBHOOK_URL } from "./settings.js"; +import * as settings from "./settings.js"; import { dynamodb } from "./instances.js"; const execute_mysql = async (input: MysqlInput) => { @@ -58,7 +59,7 @@ const execute = async (input: ProviderInput) => { export const touch = async () => { const entries = await Promise.all( - providerInputs.map(async (input) => execute(input)), + settings.providerInputs.map(async (input) => execute(input)), ); for (const entry of entries) { @@ -74,19 +75,36 @@ export const touch = async () => { // discord 기록은 실패할지 모르니까 마지막에 배치 { - const blocks = entries.map((entry) => { + const block_env = [ + "## environment", + `* NODE_ENV: ${settings.NODE_ENV}`, + `* STAGE: ${settings.STAGE}`, + ].join("\n"); + + // 성공/실패만 간단하게 보고싶다 + const lines_status = entries.map((entry) => { const { label, result } = entry; const ok = result.status === "fulfilled" ? "ok" : "error"; - const line_header = `## ${label}: ${ok}`; - const line_detail = - result.status === "fulfilled" - ? "```" + JSON.stringify(result.value, null, 2) + "```" - : "```" + JSON.stringify(result.reason, null, 2) + "```"; + return `* ${label}: ${ok}`; + }); + const block_status = ["## status", ...lines_status].join("\n"); + + // 실패는 상세 로그가 필요하다. 성공 로그는 노이즈에 불과하다. + const lines_error = entries.flatMap((entry) => { + if (entry.result.status === "fulfilled") { + return null; + } - const block = [line_header, line_detail].join("\n"); - return block; + const { label, result } = entry; + const line_header = `### ${label}`; + const line_detail = + "```" + JSON.stringify(result.reason, null, 2) + "```"; + return [line_header, line_detail]; }); - const text = blocks.join("\n\n"); + const block_error = + lines_error.length > 0 ? ["## error", ...lines_error].join("\n") : ""; + + const text = [block_env, block_status, block_error].join("\n\n"); await sendMessageToDiscord(text); } @@ -94,7 +112,7 @@ export const touch = async () => { }; export const sendMessageToDiscord = async (text: string) => { - const url = DISCORD_WEBHOOK_URL; + const url = settings.DISCORD_WEBHOOK_URL; if (!url) { return { ok: false, reason: "no webhook url" }; }