API: Health endpoint returns synchronized state

This commit is contained in:
Dennis Reimann
2020-04-21 10:39:04 +02:00
parent 3bd5c3e1b5
commit 70d1056d48
5 changed files with 44 additions and 9 deletions

View File

@@ -1,15 +1,16 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using BTCPayServer.Client.Models;
namespace BTCPayServer.Client
{
public partial class BTCPayServerClient
{
public virtual async Task<bool> IsHealthy(CancellationToken token = default)
public virtual async Task<ApiHealthData> GetHealth(CancellationToken token = default)
{
var response = await _httpClient.SendAsync(CreateHttpRequest("api/v1/health"), token);
return response.IsSuccessStatusCode;
var response = await _httpClient.SendAsync(CreateHttpRequest("api/v1/health", bodyPayload: new {}), token);
return await HandleResponse<ApiHealthData>(response);
}
}
}

View File

@@ -0,0 +1,10 @@
using BTCPayServer.Client.JsonConverters;
using Newtonsoft.Json;
namespace BTCPayServer.Client.Models
{
public class ApiHealthData
{
public bool Synchronized { get; set; }
}
}

View File

@@ -238,8 +238,9 @@ namespace BTCPayServer.Tests
await tester.StartAsync();
var unauthClient = new BTCPayServerClient(tester.PayTester.ServerUri);
var isHealthy = await unauthClient.IsHealthy();
Assert.True(isHealthy);
var apiHealthData = await unauthClient.GetHealth();
Assert.NotNull(apiHealthData);
Assert.True(apiHealthData.Synchronized);
}
}
}

View File

@@ -1,3 +1,5 @@
using BTCPayServer.HostedServices;
using BTCPayServer.Client.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -8,9 +10,10 @@ namespace BTCPayServer.Controllers.GreenField
{
[AllowAnonymous]
[HttpGet("~/api/v1/health")]
public ActionResult GetHealth()
public ActionResult GetHealth(NBXplorerDashboard dashBoard)
{
return Ok();
ApiHealthData model = new ApiHealthData() {Synchronized = dashBoard.IsFullySynched()};
return Ok(model);
}
}
}

View File

@@ -6,18 +6,38 @@
"Health"
],
"summary": "Get health status",
"description": "Check whether of not the instance is up",
"description": "Check the instance health status",
"operationId": "Health_GetHealth",
"responses": {
"200": {
"description": "Instance is up",
"content": {}
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ApplicationHealthData"
}
}
}
}
},
"security": []
}
}
},
"components": {
"schemas": {
"ApplicationHealthData": {
"type": "object",
"additionalProperties": false,
"properties": {
"synchronized": {
"type": "boolean",
"description": "True if the instance is fully synchronized"
}
}
}
}
},
"tags": [
{
"name": "Health"