public async Task Get() { using (var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync()) { using (var writer = new NotificationCenterWebSocketWriter(webSocket, Database.NotificationCenter, ContextPool, Database.DatabaseShutdown)) { using (Database.NotificationCenter.GetStored(out IEnumerable <NotificationTableValue> storedNotifications, postponed: false)) { foreach (var alert in storedNotifications) { await writer.WriteToWebSocket(alert.Json); } } foreach (var operation in Database.Operations.GetActive().OrderBy(x => x.Description.StartTime)) { var action = OperationChanged.Create(Database.Name, operation.Id, operation.Description, operation.State, operation.Killable); await writer.WriteToWebSocket(action.ToJson()); } writer.AfterTrackActionsRegistration = ServerStore.NotifyAboutClusterTopologyAndConnectivityChanges; await writer.WriteNotifications(null); } } }
public async Task Get() { using (var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync()) { var isValidFor = GetDatabaseAccessValidationFunc(); using (var writer = new NotificationCenterWebSocketWriter(webSocket, ServerStore.NotificationCenter, ServerStore.ContextPool, ServerStore.ServerShutdown)) { using (ServerStore.NotificationCenter.GetStored(out IEnumerable <NotificationTableValue> storedNotifications, postponed: false)) { foreach (var action in storedNotifications) { if (isValidFor != null) { if (action.Json.TryGet("Database", out string db) == false || isValidFor(db) == false) { continue; // not valid for this, skipping } } await writer.WriteToWebSocket(action.Json); } } foreach (var operation in ServerStore.Operations.GetActive().OrderBy(x => x.Description.StartTime)) { var action = OperationChanged.Create(null, operation.Id, operation.Description, operation.State, operation.Killable); await writer.WriteToWebSocket(action.ToJson()); } await writer.WriteNotifications(isValidFor); } } }
private void RaiseNotifications(OperationStatusChange change, Operation operation) { var operationChanged = OperationChanged.Create(_name, change.OperationId, operation.Description, change.State, operation.Killable); operation.NotifyCenter(operationChanged, x => _notificationCenter.Add(x)); _changes?.RaiseNotifications(change); }
private bool ShouldThrottleMessage(OperationChanged notification) { if (notification.State.Status != OperationStatus.InProgress) { return(false); } return(true); }
private static List <Notification> CreateSampleNotificationsForFilterOutTest() { return(new List <Notification> { AlertRaised.Create( null, "DatabaseTopologyWarning", "DatabaseTopologyWarning_MSG", AlertType.DatabaseTopologyWarning, NotificationSeverity.Info), DatabaseChanged.Create(null, DatabaseChangeType.Put), // filtered out, DatabaseChange AlertRaised.Create( null, "LicenseManager_AGPL3", "LicenseManager_AGPL3_MSG", AlertType.ClusterTransactionFailure, NotificationSeverity.Info), AlertRaised.Create( null, "LicenseManager_AGPL3", "LicenseManager_AGPL3_MSG", AlertType.LicenseManager_AGPL3, // filtered out explicitly NotificationSeverity.Info), AlertRaised.Create( null, "RevisionsConfigurationNotValid", "RevisionsConfigurationNotValid_MSG", AlertType.RevisionsConfigurationNotValid, // filtered out explicitly NotificationSeverity.Info), AlertRaised.Create( null, "Certificates_ReplaceError", "Certificates_ReplaceError_MSG", AlertType.Certificates_ReplaceError, NotificationSeverity.Info), PerformanceHint.Create( null, "SlowIO", "SlowIO_MSG", PerformanceHintType.SlowIO, // filtered out, PerformanceHint NotificationSeverity.Info, "test"), PerformanceHint.Create( null, "SqlEtl_SlowSql", "SqlEtl_SlowSql_MSG", PerformanceHintType.SqlEtl_SlowSql, // filtered out, PerformanceHint NotificationSeverity.Info, "test"), OperationChanged.Create(null, 1, new Operations.OperationDescription(), new OperationState() { Result = new PersistableResult() }, false), DatabaseChanged.Create(null, DatabaseChangeType.Delete) // filtered out, DatabaseChange }); }
public void Should_persist_operation_if_result_requires_persistance() { using (var database = CreateDocumentDatabase()) { database.NotificationCenter.Add(OperationChanged.Create(database.Name, 1, new Operations.OperationDescription(), new OperationState() { Result = new PersistableResult() }, false)); IEnumerable <NotificationTableValue> actions; using (database.NotificationCenter.GetStored(out actions)) { Assert.Equal(1, actions.Count()); } } }
private bool ShouldThrottleMessage(OperationChanged notification) { if (notification.State.Status != OperationStatus.InProgress) { return(false); } switch (notification.TaskType) { case OperationType.MigrationFromLegacyData: case OperationType.DatabaseExport: case OperationType.DatabaseImport: return(false); } return(true); }
public void NotifyCenter(OperationChanged notification, Action <OperationChanged> addToNotificationCenter) { if (ShouldThrottleMessage(notification) == false) { addToNotificationCenter(notification); return; } // let us throttle changes about the operation progress var now = SystemTime.UtcNow; _throttle.Notification = notification; var sinceLastSent = now - _throttle.SentAt; if (_throttle.Scheduled == null && sinceLastSent > _throttleTime) { addToNotificationCenter(_throttle.Notification); _throttle.SentAt = now; return; } if (_throttle.Scheduled == null) { _throttle.Scheduled = System.Threading.Tasks.Task.Delay(_throttleTime - sinceLastSent).ContinueWith(x => { if (State.Status == OperationStatus.InProgress) { addToNotificationCenter(_throttle.Notification); } _throttle.SentAt = DateTime.UtcNow; _throttle.Scheduled = null; }); } }
protected virtual void OnOperationChanged(OperationStatus operationStatus) { OperationChanged?.Invoke(this, new UpdaterOperationChangedEventArgs(operationStatus)); }
protected virtual void OnOperationChanged(OperationArgs.OperationTypes type) => OperationChanged?.Invoke(this, new OperationArgs(type));