From d3b4d59f3cd97d9bc8d4bf3eed9559d8eda7d1cd Mon Sep 17 00:00:00 2001 From: kjh2064 Date: Sun, 28 Jun 2026 16:27:07 +0900 Subject: [PATCH] fix: send Telegram deployment notification asynchronously - Move deployment completion alert to background Task - Prevent blocking app startup waiting for Telegram API - Fixes 'service not responding' errors during health check - Add error handling for Telegram send failures Co-Authored-By: Claude Haiku 4.5 --- TaxBaik.Web/Program.cs | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/TaxBaik.Web/Program.cs b/TaxBaik.Web/Program.cs index 7b90ef0..af3f5ad 100644 --- a/TaxBaik.Web/Program.cs +++ b/TaxBaik.Web/Program.cs @@ -232,14 +232,24 @@ try Log.Information("애플리케이션 시작: {Environment}", app.Environment.EnvironmentName); if (!app.Environment.IsDevelopment()) { - using (var scope = app.Services.CreateScope()) + // 배포 완료 알림을 백그라운드에서 비동기 전송 (앱 시작 블록 방지) + _ = Task.Run(async () => { - var telegramService = scope.ServiceProvider.GetRequiredService(); - // 배포 완료 알림 - await telegramService.SendInfoAsync( - "✅ 배포 완료", - $"환경: {app.Environment.EnvironmentName}\n상태: 정상 운영 중"); - } + try + { + using (var scope = app.Services.CreateScope()) + { + var telegramService = scope.ServiceProvider.GetRequiredService(); + await telegramService.SendInfoAsync( + "✅ 배포 완료", + $"환경: {app.Environment.EnvironmentName}\n상태: 정상 운영 중"); + } + } + catch (Exception ex) + { + Log.Error(ex, "배포 완료 알림 전송 실패"); + } + }); } app.Run(); } @@ -248,12 +258,19 @@ catch (Exception ex) Log.Fatal(ex, "애플리케이션 강종"); if (!app.Environment.IsDevelopment()) { - using (var scope = app.Services.CreateScope()) + try { - var telegramService = scope.ServiceProvider.GetRequiredService(); - await telegramService.SendErrorAsync( - "❌ 서버 오류", - $"환경: {app.Environment.EnvironmentName}\n오류: {ex.Message}"); + using (var scope = app.Services.CreateScope()) + { + var telegramService = scope.ServiceProvider.GetRequiredService(); + await telegramService.SendErrorAsync( + "❌ 서버 오류", + $"환경: {app.Environment.EnvironmentName}\n오류: {ex.Message}"); + } + } + catch (Exception telegramEx) + { + Log.Error(telegramEx, "오류 알림 전송 실패"); } } throw;