diff --git a/DbFirst.API/Dashboards/DashboardChangeNotifier.cs b/DbFirst.API/Dashboards/DashboardChangeNotifier.cs index eb5f049..265ed96 100644 --- a/DbFirst.API/Dashboards/DashboardChangeNotifier.cs +++ b/DbFirst.API/Dashboards/DashboardChangeNotifier.cs @@ -6,14 +6,23 @@ namespace DbFirst.API.Dashboards; public class DashboardChangeNotifier : IDashboardChangeNotifier { private readonly IHubContext _hubContext; + private readonly ILogger _logger; - public DashboardChangeNotifier(IHubContext hubContext) + public DashboardChangeNotifier(IHubContext hubContext, ILogger logger) { _hubContext = hubContext; + _logger = logger; } - public void NotifyChanged() + public async Task NotifyChangedAsync() { - _ = _hubContext.Clients.All.SendAsync("DashboardsChanged"); + try + { + await _hubContext.Clients.All.SendAsync("DashboardsChanged"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Failed to notify dashboard clients."); + } } } diff --git a/DbFirst.API/Dashboards/IDashboardChangeNotifier.cs b/DbFirst.API/Dashboards/IDashboardChangeNotifier.cs index 94ddee5..b1f6604 100644 --- a/DbFirst.API/Dashboards/IDashboardChangeNotifier.cs +++ b/DbFirst.API/Dashboards/IDashboardChangeNotifier.cs @@ -2,5 +2,5 @@ namespace DbFirst.API.Dashboards; public interface IDashboardChangeNotifier { - void NotifyChanged(); + Task NotifyChangedAsync(); } diff --git a/DbFirst.API/Dashboards/SqlDashboardStorage.cs b/DbFirst.API/Dashboards/SqlDashboardStorage.cs index 263cb60..3bfaafe 100644 --- a/DbFirst.API/Dashboards/SqlDashboardStorage.cs +++ b/DbFirst.API/Dashboards/SqlDashboardStorage.cs @@ -100,7 +100,7 @@ public sealed class SqlDashboardStorage : IEditableDashboardStorage connection.Open(); command.ExecuteNonQuery(); - _notifier?.NotifyChanged(); + _ = _notifier?.NotifyChangedAsync(); return id; } @@ -122,7 +122,7 @@ public sealed class SqlDashboardStorage : IEditableDashboardStorage throw new ArgumentException($"Dashboard '{dashboardId}' not found."); } - _notifier?.NotifyChanged(); + _ = _notifier?.NotifyChangedAsync(); } public void DeleteDashboard(string dashboardId) @@ -133,6 +133,6 @@ public sealed class SqlDashboardStorage : IEditableDashboardStorage connection.Open(); command.ExecuteNonQuery(); - _notifier?.NotifyChanged(); + _ = _notifier?.NotifyChangedAsync(); } }