feat: Health Check 엔드포인트 구현 (#24)
All checks were successful
SPMS_API/pipeline/head This commit looks good
All checks were successful
SPMS_API/pipeline/head This commit looks good
Reviewed-on: https://git.ipstein.myds.me/SPMS/SPMS_API/pulls/25
This commit is contained in:
commit
3f439e4d4e
54
SPMS.API/Controllers/PublicController.cs
Normal file
54
SPMS.API/Controllers/PublicController.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SPMS.Domain.Common;
|
||||
using SPMS.Infrastructure;
|
||||
|
||||
namespace SPMS.API.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("v1/out")]
|
||||
[AllowAnonymous]
|
||||
public class PublicController : ControllerBase
|
||||
{
|
||||
private readonly AppDbContext _dbContext;
|
||||
|
||||
public PublicController(AppDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
[HttpPost("health")]
|
||||
public async Task<IActionResult> HealthCheckAsync()
|
||||
{
|
||||
var checks = new Dictionary<string, object>();
|
||||
var allHealthy = true;
|
||||
|
||||
// 1. MariaDB 연결 확인
|
||||
try
|
||||
{
|
||||
await _dbContext.Database.ExecuteSqlRawAsync("SELECT 1");
|
||||
checks["database"] = new { status = "healthy" };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
checks["database"] = new { status = "unhealthy", error = ex.Message };
|
||||
allHealthy = false;
|
||||
}
|
||||
|
||||
// 2. Redis 연결 확인 (Phase 2에서 구현 예정)
|
||||
checks["redis"] = new { status = "not_configured" };
|
||||
|
||||
// 3. RabbitMQ 연결 확인 (Phase 2에서 구현 예정)
|
||||
checks["rabbitmq"] = new { status = "not_configured" };
|
||||
|
||||
if (allHealthy)
|
||||
{
|
||||
return Ok(ApiResponse<object>.Success(checks));
|
||||
}
|
||||
|
||||
return StatusCode(503, ApiResponse<object>.Fail(
|
||||
ErrorCodes.InternalError,
|
||||
"하나 이상의 서비스에 문제가 있습니다."));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user