@page "/" @page "/system/health" @using System.Reflection @using ErsatzTV.Application.Health @using ErsatzTV.Core.Health @using ErsatzTV.Core.Interfaces.GitHub @using Microsoft.Extensions.Caching.Memory @implements IDisposable @inject IGitHubApiClient GitHubApiClient @inject IMemoryCache MemoryCache @inject IMediator Mediator @inject SystemStartup SystemStartup;
@if (!SystemStartup.IsDatabaseReady) { Database is initializing Please wait, this may take a few minutes. This page will automatically refresh when the database is ready. } else if (!SystemStartup.IsSearchIndexReady) { Search Index is initializing Please wait, this may take a few minutes. This page will automatically refresh when the search index is ready. } else { Health Checks Check Message
@if (context.Status == HealthCheckStatus.Fail) { } else if (context.Status == HealthCheckStatus.Warning) { } else if (context.Status == HealthCheckStatus.Info) { } else { }
@context.Title
@if (context.Link.IsSome) { foreach (string link in context.Link) { @context.Message } } else { @context.Message }
Full changelog is available on GitHub }
@code { private readonly CancellationTokenSource _cts = new(); private string _releaseNotes; private MudTable _table; protected override void OnInitialized() { SystemStartup.OnDatabaseReady += OnStartupProgress; SystemStartup.OnSearchIndexReady += OnStartupProgress; } public void Dispose() { SystemStartup.OnDatabaseReady -= OnStartupProgress; SystemStartup.OnSearchIndexReady -= OnStartupProgress; _cts.Cancel(); _cts.Dispose(); } private async void OnStartupProgress(object sender, EventArgs e) { try { await InvokeAsync(StateHasChanged); } catch (Exception) { // do nothing } } protected override async Task OnParametersSetAsync() { try { if (MemoryCache.TryGetValue("Index.ReleaseNotesHtml", out string releaseNotesHtml)) { _releaseNotes = releaseNotesHtml; } else { var assembly = Assembly.GetEntryAssembly(); if (assembly != null) { string version = assembly.GetCustomAttribute()?.InformationalVersion; if (version != null) { Either maybeNotes; if (version != "develop") { string gitHubVersion = version.Split("-").Head(); if (!gitHubVersion.StartsWith("v")) { gitHubVersion = $"v{gitHubVersion}"; } maybeNotes = await GitHubApiClient.GetReleaseNotes(gitHubVersion, _cts.Token); foreach (string notes in maybeNotes.RightToSeq()) { _releaseNotes = notes; } } else { maybeNotes = await GitHubApiClient.GetLatestReleaseNotes(_cts.Token); foreach (string notes in maybeNotes.RightToSeq()) { _releaseNotes = notes; } } } } if (_releaseNotes != null) { MemoryCache.Set("Index.ReleaseNotesHtml", _releaseNotes); } } } catch (Exception) { // ignore } } private async Task> ServerReload(TableState state, CancellationToken cancellationToken) { List healthCheckResults = await Mediator.Send(new GetAllHealthCheckResults(), _cts.Token); return new TableData { TotalItems = healthCheckResults.Count, Items = healthCheckResults }; } }