mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
API: Health endpoint returns synchronized state
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
10
BTCPayServer.Client/Models/ApiHealthData.cs
Normal file
10
BTCPayServer.Client/Models/ApiHealthData.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using BTCPayServer.Client.JsonConverters;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace BTCPayServer.Client.Models
|
||||
{
|
||||
public class ApiHealthData
|
||||
{
|
||||
public bool Synchronized { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user