This commit is contained in:
42
server/AyaNova/Controllers/HealthController.cs
Normal file
42
server/AyaNova/Controllers/HealthController.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Routing;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||||
|
using Swashbuckle.AspNetCore.Annotations;
|
||||||
|
|
||||||
|
namespace AyaNova.Api.Controllers
|
||||||
|
{
|
||||||
|
[ApiController]
|
||||||
|
[ApiVersion("8.0")]
|
||||||
|
[Route("api/v{version:apiVersion}/health")]
|
||||||
|
[Produces("text/plain")]
|
||||||
|
[Authorize]
|
||||||
|
public class HealthController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly HealthCheckService _healthCheckService;
|
||||||
|
public HealthController(HealthCheckService healthCheckService)
|
||||||
|
{
|
||||||
|
_healthCheckService = healthCheckService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get Health
|
||||||
|
/// Also available at /health on server root
|
||||||
|
/// confirms liveness and also db availability
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>Provides an indication about the health of the API</remarks>
|
||||||
|
/// <response code="200">API is healthy</response>
|
||||||
|
/// <response code="503">API is unhealthy or in degraded state</response>
|
||||||
|
[HttpGet]
|
||||||
|
[AllowAnonymous]
|
||||||
|
[ProducesResponseType(typeof(string), 200)]
|
||||||
|
[SwaggerOperation(OperationId = "Health_Get")]
|
||||||
|
public async Task<IActionResult> Get()
|
||||||
|
{
|
||||||
|
var report = await _healthCheckService.CheckHealthAsync();
|
||||||
|
Response.Headers.Add("Cache-Control", "no-store, no-cache");
|
||||||
|
return report.Status == HealthStatus.Healthy ? Ok(report.Status.ToString()) : StatusCode(503, report.Status.ToString());
|
||||||
|
}
|
||||||
|
}//eoc
|
||||||
|
}//eons
|
||||||
@@ -14,7 +14,7 @@ using Newtonsoft.Json.Linq;
|
|||||||
using AyaNova.Models;
|
using AyaNova.Models;
|
||||||
using AyaNova.Api.ControllerHelpers;
|
using AyaNova.Api.ControllerHelpers;
|
||||||
using AyaNova.Biz;
|
using AyaNova.Biz;
|
||||||
using StackExchange.Profiling;
|
//using StackExchange.Profiling;
|
||||||
|
|
||||||
namespace AyaNova.Api.Controllers
|
namespace AyaNova.Api.Controllers
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using NLog.Web;
|
|||||||
using NLog.Targets;
|
using NLog.Targets;
|
||||||
using NLog.Config;
|
using NLog.Config;
|
||||||
using AyaNova.Util;
|
using AyaNova.Util;
|
||||||
using StackExchange.Profiling;
|
//using StackExchange.Profiling;
|
||||||
|
|
||||||
namespace AyaNova
|
namespace AyaNova
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ using AyaNova.Biz;
|
|||||||
using NLog.Extensions.Logging;
|
using NLog.Extensions.Logging;
|
||||||
using StackExchange.Profiling;
|
using StackExchange.Profiling;
|
||||||
|
|
||||||
|
|
||||||
namespace AyaNova
|
namespace AyaNova
|
||||||
{
|
{
|
||||||
public class Startup
|
public class Startup
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using Microsoft.Extensions.Logging;
|
|||||||
using AyaNova.Util;
|
using AyaNova.Util;
|
||||||
using AyaNova.Models;
|
using AyaNova.Models;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using StackExchange.Profiling;
|
//using StackExchange.Profiling;
|
||||||
|
|
||||||
|
|
||||||
namespace AyaNova.Biz
|
namespace AyaNova.Biz
|
||||||
|
|||||||
Reference in New Issue
Block a user