From 5abb5ada4991142e871dcfa94c32c8e4cb0ea247 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 19 Feb 2023 19:23:26 -0600 Subject: [PATCH] New: Ping Endpoint --- src/Prowlarr.Http/Ping/PingController.cs | 46 ++++++++++++++++++++++++ src/Prowlarr.Http/Ping/PingResource.cs | 7 ++++ 2 files changed, 53 insertions(+) create mode 100644 src/Prowlarr.Http/Ping/PingController.cs create mode 100644 src/Prowlarr.Http/Ping/PingResource.cs diff --git a/src/Prowlarr.Http/Ping/PingController.cs b/src/Prowlarr.Http/Ping/PingController.cs new file mode 100644 index 000000000..d36f958a1 --- /dev/null +++ b/src/Prowlarr.Http/Ping/PingController.cs @@ -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> _cache; + + public PingController(IConfigRepository configRepository, ICacheManager cacheManager) + { + _configRepository = configRepository; + _cache = cacheManager.GetCache>(GetType()); + } + + [AllowAnonymous] + [HttpGet("/ping")] + [Produces("application/json")] + public ActionResult 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" + }); + } + } +} diff --git a/src/Prowlarr.Http/Ping/PingResource.cs b/src/Prowlarr.Http/Ping/PingResource.cs new file mode 100644 index 000000000..3a8b7fbfa --- /dev/null +++ b/src/Prowlarr.Http/Ping/PingResource.cs @@ -0,0 +1,7 @@ +namespace Prowlarr.Http.Ping +{ + public class PingResource + { + public string Status { get; set; } + } +}