fix(adminui): /alarms-historian says when the role runs no historian; Fleet-style lifecycle (R04 L3)
A bare catch {} turned every failure - including an admin-only node with no
historian actor - into 'Loading...' forever, and a tick queued after a sync
timer dispose still issued an Ask. HistorianSinkStatusReader classifies a poll
as Available / NotOnThisRole (permanent: shown once, polling stops) /
Unavailable (shown with the last good status and its read time). The page
follows Fleet.razor: IAsyncDisposable, _disposed, overlap guard, page CTS.
Refs #745
Claude-Session: https://claude.ai/code/session_01Ub9hGmYLQvn9XETzw7CMsT
This commit is contained in:
@@ -5,11 +5,12 @@
|
||||
@rendermode RenderMode.InteractiveServer
|
||||
@using Akka.Actor
|
||||
@using Akka.Hosting
|
||||
@using ZB.MOM.WW.OtOpcUa.AdminUI.Clients
|
||||
@using ZB.MOM.WW.OtOpcUa.Core.AlarmHistorian
|
||||
@using ZB.MOM.WW.OtOpcUa.Runtime
|
||||
@using ZB.MOM.WW.OtOpcUa.Runtime.Historian
|
||||
@inject IRequiredActor<HistorianAdapterActorKey> HistorianActor
|
||||
@implements IDisposable
|
||||
@implements IAsyncDisposable
|
||||
|
||||
<PageErrorBoundary>
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
@@ -18,12 +19,26 @@
|
||||
|
||||
<div class="text-muted small mb-3">Polling every @PollSeconds s.</div>
|
||||
|
||||
@if (_status is null)
|
||||
@if (_reading is { Availability: HistorianSinkAvailability.NotOnThisRole })
|
||||
{
|
||||
<section class="panel notice rise mt-3" style="animation-delay:.04s">@_reading.Message</section>
|
||||
}
|
||||
else if (_status is null && _reading is { Availability: HistorianSinkAvailability.Unavailable })
|
||||
{
|
||||
<section class="panel notice notice-alert rise mt-3" style="animation-delay:.04s">@_reading.Message Retrying every @PollSeconds s.</section>
|
||||
}
|
||||
else if (_status is null)
|
||||
{
|
||||
<p class="mt-3">Loading…</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
@if (_reading is { Availability: HistorianSinkAvailability.Unavailable })
|
||||
{
|
||||
<section class="panel notice notice-alert rise mt-3" style="animation-delay:.04s">
|
||||
@_reading.Message Showing the last status read at @_statusReadUtc?.ToString("u").
|
||||
</section>
|
||||
}
|
||||
<section class="card-grid rise mt-3" style="animation-delay:.08s">
|
||||
<div class="metric-card">
|
||||
<div class="panel-head">Queue</div>
|
||||
@@ -49,30 +64,48 @@ else
|
||||
@code {
|
||||
private const int PollSeconds = 5;
|
||||
|
||||
// The Fleet.razor lifecycle (R04 L3): IAsyncDisposable, a _disposed flag, an overlap guard and a
|
||||
// page-lifetime CTS, so a queued tick after teardown neither Asks nor renders.
|
||||
private HistorianSinkStatus? _status;
|
||||
private DateTime? _statusReadUtc;
|
||||
private HistorianSinkReading? _reading;
|
||||
private Timer? _timer;
|
||||
private int _tickRunning;
|
||||
private readonly CancellationTokenSource _cts = new();
|
||||
private volatile bool _disposed;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await RefreshAsync();
|
||||
// No historian on this role is permanent — don't poll for it.
|
||||
if (_reading?.Availability == HistorianSinkAvailability.NotOnThisRole) return;
|
||||
_timer = new Timer(_ => _ = InvokeAsync(RefreshAsync), null,
|
||||
TimeSpan.FromSeconds(PollSeconds), TimeSpan.FromSeconds(PollSeconds));
|
||||
}
|
||||
|
||||
private async Task RefreshAsync()
|
||||
{
|
||||
if (_disposed || Interlocked.Exchange(ref _tickRunning, 1) == 1) return;
|
||||
try
|
||||
{
|
||||
_status = await HistorianActor.ActorRef.Ask<HistorianSinkStatus>(
|
||||
HistorianAdapterActor.GetStatus.Instance, TimeSpan.FromSeconds(2));
|
||||
StateHasChanged();
|
||||
_reading = await HistorianSinkStatusReader.ReadAsync(
|
||||
() => HistorianActor.ActorRef, HistorianSinkStatusReader.AskTimeout, _cts.Token);
|
||||
if (_reading.Status is not null)
|
||||
{
|
||||
_status = _reading.Status;
|
||||
_statusReadUtc = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
catch
|
||||
catch (Exception ex) when (ex is OperationCanceledException or ObjectDisposedException)
|
||||
{
|
||||
// Actor unavailable (admin-only node, not driver-role) — leave _status null and let
|
||||
// the page show "Loading…". A dedicated "this role doesn't run a historian" message
|
||||
// would be nicer; lands when we add role gating to the UI.
|
||||
return; // the page went away mid-Ask
|
||||
}
|
||||
finally
|
||||
{
|
||||
Volatile.Write(ref _tickRunning, 0);
|
||||
}
|
||||
|
||||
if (!_disposed) StateHasChanged();
|
||||
}
|
||||
|
||||
private static string StateChipClass(HistorianDrainState state) => state switch
|
||||
@@ -84,5 +117,13 @@ else
|
||||
_ => "chip chip-idle",
|
||||
};
|
||||
|
||||
public void Dispose() => _timer?.Dispose();
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
_disposed = true;
|
||||
_cts.Cancel();
|
||||
// Drains an in-flight callback (System.Threading.Timer async dispose, .NET 6+). The callback only
|
||||
// schedules the tick, so a tick may still hold _cts — skip the dispose then (see Hosts.razor).
|
||||
if (_timer is not null) await _timer.DisposeAsync();
|
||||
if (Volatile.Read(ref _tickRunning) == 0) _cts.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user