feat(notification-outbox): add CommunicationService outbox methods

This commit is contained in:
Joseph Doherty
2026-05-19 02:51:11 -04:00
parent 1d495d1a87
commit afdf581e32
3 changed files with 192 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ using ScadaLink.Commons.Messages.Health;
using ScadaLink.Commons.Messages.InboundApi;
using ScadaLink.Commons.Messages.Integration;
using ScadaLink.Commons.Messages.Lifecycle;
using ScadaLink.Commons.Messages.Notification;
using ScadaLink.Commons.Messages.RemoteQuery;
using ScadaLink.Communication.Actors;
@@ -23,6 +24,7 @@ public class CommunicationService
private readonly CommunicationOptions _options;
private readonly ILogger<CommunicationService> _logger;
private IActorRef? _centralCommunicationActor;
private IActorRef? _notificationOutboxProxy;
public CommunicationService(
IOptions<CommunicationOptions> options,
@@ -40,6 +42,16 @@ public class CommunicationService
_centralCommunicationActor = centralCommunicationActor;
}
/// <summary>
/// Sets the notification-outbox singleton proxy reference. Called during actor
/// system startup. The outbox actor is central-local, so outbox calls Ask this
/// proxy directly (no SiteEnvelope routing).
/// </summary>
public void SetNotificationOutbox(IActorRef notificationOutboxProxy)
{
_notificationOutboxProxy = notificationOutboxProxy;
}
/// <summary>
/// Triggers an immediate refresh of the site address cache from the database.
/// </summary>
@@ -59,6 +71,15 @@ public class CommunicationService
private IActorRef GetActor() => GetCommunicationActor();
/// <summary>
/// Gets the notification-outbox proxy reference. Throws if not yet initialized.
/// </summary>
private IActorRef GetNotificationOutbox()
{
return _notificationOutboxProxy
?? throw new InvalidOperationException("CommunicationService not initialized. NotificationOutbox proxy not set.");
}
// ── Pattern 1: Instance Deployment ──
public async Task<DeploymentStatusResponse> DeployInstanceAsync(
@@ -230,6 +251,36 @@ public class CommunicationService
return await GetActor().Ask<RouteToSetAttributesResponse>(
envelope, _options.IntegrationTimeout, cancellationToken);
}
// ── Notification Outbox (central-local actor — Asked directly, no SiteEnvelope) ──
public async Task<NotificationOutboxQueryResponse> QueryNotificationOutboxAsync(
NotificationOutboxQueryRequest request, CancellationToken cancellationToken = default)
{
return await GetNotificationOutbox().Ask<NotificationOutboxQueryResponse>(
request, _options.QueryTimeout, cancellationToken);
}
public async Task<RetryNotificationResponse> RetryNotificationAsync(
RetryNotificationRequest request, CancellationToken cancellationToken = default)
{
return await GetNotificationOutbox().Ask<RetryNotificationResponse>(
request, _options.QueryTimeout, cancellationToken);
}
public async Task<DiscardNotificationResponse> DiscardNotificationAsync(
DiscardNotificationRequest request, CancellationToken cancellationToken = default)
{
return await GetNotificationOutbox().Ask<DiscardNotificationResponse>(
request, _options.QueryTimeout, cancellationToken);
}
public async Task<NotificationKpiResponse> GetNotificationKpisAsync(
NotificationKpiRequest request, CancellationToken cancellationToken = default)
{
return await GetNotificationOutbox().Ask<NotificationKpiResponse>(
request, _options.QueryTimeout, cancellationToken);
}
}
/// <summary>

View File

@@ -288,6 +288,10 @@ akka {{
// Hand the outbox proxy to the CentralCommunicationActor so forwarded
// NotificationSubmit messages from sites are routed to the outbox singleton.
centralCommActor.Tell(new RegisterNotificationOutbox(outboxProxy));
// Hand the same proxy to the CommunicationService so the Central UI can
// Ask the outbox actor directly (query, retry, discard, KPIs).
commService?.SetNotificationOutbox(outboxProxy);
_logger.LogInformation("NotificationOutbox singleton created and registered with CentralCommunicationActor");
_logger.LogInformation("Central actors registered. CentralCommunicationActor created.");