/// <summary> /// Runs the notification task. /// The task will continue to run indefinitely until the cancellationToken is canceled. /// </summary> /// <param name="connectorConfig"></param> /// <param name="logPrefix"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task RunAsync(ConnectorConfigModel connectorConfig, string logPrefix, CancellationToken cancellationToken) { // Set up properties that will be used consistently by multiple methods _connectorConfig = connectorConfig; _cancellationToken = cancellationToken; _logPrefix = logPrefix; _authenticationHelperSettings = AuthenticationHelperSettingsFactory(connectorConfig); while (!cancellationToken.IsCancellationRequested) { // Get all pending notifications var notifications = await NotificationPullManager.GetAllPendingConnectorNotifications( ApiClientFactorySettings, _authenticationHelperSettings, _connectorConfig.Id, _cancellationToken).ConfigureAwait(false); // Process all pending notifications foreach (var notification in notifications) { if (cancellationToken.IsCancellationRequested) { break; } await ProcessNotification(notification).ConfigureAwait(false); } // Wait the prescribed period of time before polling for more new Notifications await Task.Delay(TimeSpan.FromSeconds(NotificationRunnerSettings?.NotificationPollIntervalSeconds ?? NotificationRunnerSettings.DefaultNotificationPollIntervalSeconds)).ConfigureAwait(false); } }
private async Task AcknowledgeNotification(ConnectorNotificationModel model, ProcessingResult processingResult, string message) { try { await NotificationPullManager.AcknowledgeNotification( ApiClientFactorySettings, AuthenticationHelperSettingsFactory(_connectorConfig), model.ToAcknowledge(processingResult, message)).ConfigureAwait(false); } catch (ResourceNotFoundException) { // The notification couldn't be acked because it wasn't found. // This may happen if the notification was already acked - in this case, // the next iteration of the poller won't receive this notification again. Log?.LogWarning(GetType(), nameof(AcknowledgeNotification), $"{_logPrefix} - Notification with ID [{model.Id}] was not acknowledged because it could not be found " + "in the Records365 notification queue. It may have already been acknowledged."); } }