fix(health): acked SendAsync transport — report-loss counter restore is live, not dead code

This commit is contained in:
Joseph Doherty
2026-07-08 16:12:48 -04:00
parent 17af376a8e
commit 6300d6d399
5 changed files with 142 additions and 16 deletions
@@ -6,13 +6,17 @@ using ZB.MOM.WW.ScadaBridge.Host.Actors;
namespace ZB.MOM.WW.ScadaBridge.Host;
/// <summary>
/// Sends SiteHealthReport to the local SiteCommunicationActor via Akka ActorSelection.
/// The SiteCommunicationActor forwards it to central.
/// Sends SiteHealthReport to the local SiteCommunicationActor via Akka ActorSelection,
/// which forwards it to central. The send is an acked round-trip (review 01 [Medium]):
/// it Asks and awaits the central <see cref="SiteHealthReportAck"/>, so a lost or
/// rejected report faults the sender's task (driving its counter-restore path).
/// </summary>
public class AkkaHealthReportTransport : IHealthReportTransport
{
private readonly AkkaHostedService _akkaService;
private static readonly TimeSpan AckTimeout = TimeSpan.FromSeconds(10);
/// <summary>
/// Initializes a new <see cref="AkkaHealthReportTransport"/> backed by the given Akka hosted service.
/// </summary>
@@ -23,12 +27,15 @@ public class AkkaHealthReportTransport : IHealthReportTransport
}
/// <inheritdoc />
public void Send(SiteHealthReport report)
public async Task SendAsync(SiteHealthReport report, CancellationToken cancellationToken)
{
var actorSystem = _akkaService.ActorSystem;
if (actorSystem == null) return;
var actorSystem = _akkaService.ActorSystem
?? throw new InvalidOperationException("Actor system not started — health report not sent");
var siteComm = actorSystem.ActorSelection("/user/site-communication");
siteComm.Tell(report, ActorRefs.NoSender);
var ack = await siteComm.Ask<SiteHealthReportAck>(report, AckTimeout, cancellationToken)
.ConfigureAwait(false);
if (!ack.Accepted)
throw new InvalidOperationException($"Health report #{report.SequenceNumber} rejected: {ack.Error}");
}
}