You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/src/Lidarr.Http/Ping/PingController.cs

47 lines
1.3 KiB

using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NzbDrone.Common.Cache;
using NzbDrone.Core.Configuration;
namespace Lidarr.Http.Ping
{
public class PingController : Controller
{
private readonly IConfigRepository _configRepository;
private readonly ICached<IEnumerable<Config>> _cache;
public PingController(IConfigRepository configRepository, ICacheManager cacheManager)
{
_configRepository = configRepository;
_cache = cacheManager.GetCache<IEnumerable<Config>>(GetType());
}
[AllowAnonymous]
[HttpGet("/ping")]
[HttpHead("/ping")]
[Produces("application/json")]
public ActionResult<PingResource> GetStatus()
{
try
{
_cache.Get("ping", _configRepository.All, TimeSpan.FromSeconds(5));
}
catch (Exception)
{
return StatusCode(StatusCodes.Status500InternalServerError, new PingResource
{
Status = "Error"
});
}
return StatusCode(StatusCodes.Status200OK, new PingResource
{
Status = "OK"
});
}
}
}