fix(adminui): snapshot already old at dialog open is stale immediately (#857)
The Controls panel primed its per-node view from the snapshot store with ReceivedUtc = now, so a node that stopped publishing before the dialog opened looked live for the first 30 s stale window. InMemoryDriverStatusSnapshotStore now records each snapshot's LOCAL receive time (TimeProvider-injectable) and exposes it via GetAllWithReceiveTime(); the panel primes through the pure seam DriverStatusByNode.Prime/PrimedReceiveTime, which keeps the store's receive time (clamped to now; still skew-proof). A store that does not track one (default interface impl -> null) falls back to the publish time only when that is already older than the stale window, else now. Claude-Session: https://claude.ai/code/session_01GT67AD99zQQqpLCVm3p7xk
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Hubs;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Messages.Drivers;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Hosts;
|
||||
@@ -67,6 +68,43 @@ public sealed class DriverStatusByNode
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Primes the view from the snapshot store's current contents (lmxopcua#857). Each snapshot keeps the
|
||||
/// store's own receive time (<see cref="PrimedReceiveTime"/>) rather than "now", so a node that stopped
|
||||
/// publishing before the dialog opened is stale immediately instead of looking live for a full
|
||||
/// <paramref name="staleAfter"/> window. Returns true when the view changed.
|
||||
/// </summary>
|
||||
/// <param name="stored">The store's entries (<see cref="IDriverStatusSnapshotStore.GetAllWithReceiveTime"/>).</param>
|
||||
/// <param name="nowUtc">The local time the view is primed at.</param>
|
||||
/// <param name="staleAfter">The view's stale window (only used when the store has no receive time).</param>
|
||||
public bool Prime(IEnumerable<StoredDriverHealth> stored, DateTime nowUtc, TimeSpan staleAfter)
|
||||
{
|
||||
var changed = false;
|
||||
foreach (var entry in stored)
|
||||
changed |= Upsert(entry.Snapshot, PrimedReceiveTime(entry, nowUtc, staleAfter));
|
||||
return changed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The receive time a snapshot primed from the store is aged from (lmxopcua#857). Prefers the store's
|
||||
/// LOCAL receive time — same clock as live updates, so still skew-proof — clamped to
|
||||
/// <paramref name="nowUtc"/>. A store that does not track receive times falls back to the publisher's
|
||||
/// <see cref="DriverHealthChanged.PublishedUtc"/> only when that is already older than the stale window
|
||||
/// (so a long-silent node is stale at once; a peer clock running behind can at worst dim a live row until
|
||||
/// its next publish), else to <paramref name="nowUtc"/> (the pre-#857 behaviour).
|
||||
/// </summary>
|
||||
/// <param name="stored">The store entry.</param>
|
||||
/// <param name="nowUtc">The local time the view is primed at.</param>
|
||||
/// <param name="staleAfter">The view's stale window.</param>
|
||||
public static DateTime PrimedReceiveTime(StoredDriverHealth stored, DateTime nowUtc, TimeSpan staleAfter)
|
||||
{
|
||||
if (stored.ReceivedUtc is { } received)
|
||||
return received > nowUtc ? nowUtc : received;
|
||||
|
||||
var published = stored.Snapshot.PublishedUtc;
|
||||
return nowUtc - published > staleAfter ? published : nowUtc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A point-in-time copy of every node's entry, ordered by node id (ordinal, case-insensitive) with the
|
||||
/// unlabelled (pre-#847) entry last.
|
||||
|
||||
Reference in New Issue
Block a user