mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-12-26 00:16:02 +01:00
New: Ping Endpoint
This commit is contained in:
46
src/Prowlarr.Http/Ping/PingController.cs
Normal file
46
src/Prowlarr.Http/Ping/PingController.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
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;
|
||||
using Prowlarr.Http.Ping;
|
||||
|
||||
namespace Prowlarr.Http
|
||||
{
|
||||
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")]
|
||||
[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"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
7
src/Prowlarr.Http/Ping/PingResource.cs
Normal file
7
src/Prowlarr.Http/Ping/PingResource.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Prowlarr.Http.Ping
|
||||
{
|
||||
public class PingResource
|
||||
{
|
||||
public string Status { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user