Implemented container helper status checked. Started implementing container helper ui. Improved update modal

This commit is contained in:
2026-01-25 22:51:51 +01:00
parent e2f344ab4e
commit 4e96905fb2
7 changed files with 152 additions and 37 deletions

View File

@@ -1,6 +1,9 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Moonlight.Api.Configuration;
using Moonlight.Api.Services;
using Moonlight.Shared.Http.Responses.Admin;
namespace Moonlight.Api.Http.Controllers.Admin;
@@ -9,10 +12,23 @@ namespace Moonlight.Api.Http.Controllers.Admin;
public class ChController : Controller
{
private readonly ContainerHelperService ContainerHelperService;
private readonly IOptions<ContainerHelperOptions> Options;
public ChController(ContainerHelperService containerHelperService)
public ChController(ContainerHelperService containerHelperService, IOptions<ContainerHelperOptions> options)
{
ContainerHelperService = containerHelperService;
Options = options;
}
[HttpGet("status")]
public async Task<ActionResult<ContainerHelperStatusDto>> GetStatusAsync()
{
if (!Options.Value.IsEnabled)
return new ContainerHelperStatusDto(false, false);
var status = await ContainerHelperService.CheckConnectionAsync();
return new ContainerHelperStatusDto(true, status);
}
[HttpPost("rebuild")]

View File

@@ -13,6 +13,23 @@ public class ContainerHelperService
HttpClientFactory = httpClientFactory;
}
public async Task<bool> CheckConnectionAsync()
{
var client = HttpClientFactory.CreateClient("ContainerHelper");
try
{
var response = await client.GetAsync("api/ping");
response.EnsureSuccessStatusCode();
return true;
}
catch (Exception)
{
return false;
}
}
public async IAsyncEnumerable<RebuildEvent> RebuildAsync()
{
var options = new JsonSerializerOptions()
@@ -29,6 +46,7 @@ public class ContainerHelperService
if (!response.IsSuccessStatusCode)
{
var responseText = await response.Content.ReadAsStringAsync();
yield return new RebuildEvent()
{
Type = RebuildEventType.Failed,
@@ -56,6 +74,11 @@ public class ContainerHelperService
var deserializedData = JsonSerializer.Deserialize<RebuildEvent>(data, options);
yield return deserializedData;
// Exit if service will go down for a clean exit
if(deserializedData is {Type: RebuildEventType.Step, Data: "ServiceDown"})
yield break;
} while (true);
yield return new RebuildEvent()