662f3f9f5c
v2-ci / build (push) Failing after 32s
v2-ci / unit-tests (tests/Core/ZB.MOM.WW.OtOpcUa.Cluster.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.ControlPlane.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.Security.Tests) (push) Has been skipped
v2-ci / integration (tests/Server/ZB.MOM.WW.OtOpcUa.Host.IntegrationTests) (push) Has been skipped
v2-ci / integration (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.IntegrationTests) (push) Has been skipped
- Topic-name drift fix: DriverHealthChanged.TopicName and DriverControlTopic.Name now live on the message contracts in Commons. AkkaDriverHealthPublisher, DriverStatusSignalRBridge, DriverHostActor, and AdminOperationsActor all delegate to the single constant so a rename can't silently desynchronise publisher and subscriber. - DriverStatusPanel._opResultClearTimer switched from System.Timers.Timer to System.Threading.Timer + awaited DisposeAsync. Prevents an in-flight 8s clear-callback from invoking StateHasChanged on a component whose hub has already been released. - PublishHealthSnapshot deduplicates against the last published (state, lastSuccess, lastError, errorCount) fingerprint. The 30s heartbeat no longer floods the SignalR layer with identical Healthy snapshots — newly-joined clients still warm up via the snapshot store on JoinDriver.
59 lines
2.5 KiB
C#
59 lines
2.5 KiB
C#
using Akka.Actor;
|
|
using Akka.Cluster.Tools.PublishSubscribe;
|
|
using Akka.Event;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using ZB.MOM.WW.OtOpcUa.Commons.Messages.Drivers;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Hubs;
|
|
|
|
/// <summary>
|
|
/// Akka actor that subscribes to the <c>driver-health</c> DistributedPubSub topic and
|
|
/// forwards every <see cref="DriverHealthChanged"/> snapshot to (a) the in-memory snapshot
|
|
/// store and (b) all SignalR clients connected to <see cref="DriverStatusHub"/> grouped
|
|
/// by <see cref="DriverHealthChanged.DriverInstanceId"/>. Spawned on admin-role nodes by
|
|
/// <c>AddOtOpcUaSignalRBridges</c>.
|
|
/// </summary>
|
|
public sealed class DriverStatusSignalRBridge : ReceiveActor
|
|
{
|
|
public const string TopicName = DriverHealthChanged.TopicName;
|
|
|
|
private readonly IHubContext<DriverStatusHub> _hub;
|
|
private readonly IDriverStatusSnapshotStore _store;
|
|
private readonly ILoggingAdapter _log = Context.GetLogger();
|
|
|
|
/// <summary>Creates actor props for a <see cref="DriverStatusSignalRBridge"/>.</summary>
|
|
/// <param name="hub">The SignalR hub context for pushing snapshots to grouped clients.</param>
|
|
/// <param name="store">Snapshot store updated before each SignalR push.</param>
|
|
public static Props Props(IHubContext<DriverStatusHub> hub, IDriverStatusSnapshotStore store) =>
|
|
Akka.Actor.Props.Create(() => new DriverStatusSignalRBridge(hub, store));
|
|
|
|
/// <summary>Initializes a new instance of <see cref="DriverStatusSignalRBridge"/>.</summary>
|
|
/// <param name="hub">The SignalR hub context for pushing snapshots to grouped clients.</param>
|
|
/// <param name="store">Snapshot store updated before each SignalR push.</param>
|
|
public DriverStatusSignalRBridge(IHubContext<DriverStatusHub> hub, IDriverStatusSnapshotStore store)
|
|
{
|
|
_hub = hub;
|
|
_store = store;
|
|
ReceiveAsync<DriverHealthChanged>(ForwardAsync);
|
|
Receive<SubscribeAck>(_ => { /* DPS confirmation */ });
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void PreStart() =>
|
|
DistributedPubSub.Get(Context.System).Mediator.Tell(new Subscribe(TopicName, Self));
|
|
|
|
private async Task ForwardAsync(DriverHealthChanged msg)
|
|
{
|
|
try
|
|
{
|
|
_store.Upsert(msg);
|
|
await _hub.Clients.Group(DriverStatusHub.GroupName(msg.DriverInstanceId))
|
|
.SendAsync(DriverStatusHub.MethodName, msg);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_log.Warning(ex, "DriverStatusSignalRBridge: SignalR push failed (instance={Instance})", msg.DriverInstanceId);
|
|
}
|
|
}
|
|
}
|