using System; using System.Threading; using System.Threading.Tasks; using FrameworkBLL.GOP; using GB5Shared.DTO.GOP; using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Logging; namespace FrameworkSL.Hubs.GOP { // ============================================================ // GopHubNotifier — SL implementation of IGopHubNotifier. // // Wraps IHubContext so // that FrameworkBLL (the pipeline) can push real-time status // updates to connected SignalR clients without referencing any // ASP.NET types directly. // // Registration: // services.AddSingleton(); // (Singleton is safe: IHubContext is registered as Singleton // and is thread-safe.) // ============================================================ public class GopHubNotifier : IGopHubNotifier { private readonly IHubContext _HubContext; private readonly ILogger _Logger; public GopHubNotifier( IHubContext hubContext, ILogger logger) { _HubContext = hubContext; _Logger = logger; } public async Task PushExecutionUpdate( int clientId, GopExecutionStatusDTO status, CancellationToken ct = default) { try { await _HubContext.Clients .Group(GopExecutionHub.TenantGroup(clientId)) .ReceiveExecutionUpdate(status); } catch (Exception ex) { // Hub push failures are non-fatal — log and continue. _Logger.LogWarning(ex, "GopHubNotifier: failed to push execution update for execution {ExecutionId}", status.ExecutionId); } } public async Task PushDLQUpdate( int clientId, GopDLQSummaryDTO summary, CancellationToken ct = default) { try { await _HubContext.Clients .Group(GopExecutionHub.TenantGroup(clientId)) .ReceiveDLQUpdate(summary); } catch (Exception ex) { _Logger.LogWarning(ex, "GopHubNotifier: failed to push DLQ update for execution {ExecutionId}", summary.ExecutionId); } } } }