public void StartNotificationProcessing(IEventStoreConnection connection) { Require.NotNull(connection, "connection"); if (m_subscriptions.Any()) { m_maxProcessingCount = Constants.Settings.MAX_NOTIFICATION_PROCESSING_COUNT * m_subscriptions.Count; foreach (var subscriptions in m_subscriptions.Values) { subscriptions.Start(connection); } m_notificationProcessor.RegisterHandlers(m_subscriptions.Values); m_pollingJob.Start(async token => { var notifications = await ReceiveNotificationsAsync(); if (notifications.IsEmpty()) { s_logger.Debug("No notifications for processing."); return(false); } foreach (var notification in notifications) { m_notificationProcessor.Process(notification); } return(true); }); } }
public void Start() { s_logger.Information("Starting pending notifications chaser..."); m_pollingJob.Start(async cancellationToken => { var lease = Lease.NotAcquired; var result = false; try { lease = await Lease.AcquireAsync( m_chaserExclusiveAccessBlobLock, TimeSpan.FromMinutes(Constants.Settings.PENDING_NOTIFICATIONS_CHASER_EXCLUSIVE_ACCESS_LOCK_TIMEOUT_IN_MINUTES)); if (Lease.IsAcquired(lease)) { s_logger.Verbose("Chaser lock was successfully acquired. Start pending notification processing..."); var processNotificationCount = await ProcessPendingNotificationsAsync(); s_logger.Information("Chaser republished {NotificationCount} unpublished notifications.", processNotificationCount); result = processNotificationCount != 0; } else { s_logger.Verbose("Chaser lock wasn't acquired."); } } catch (Exception exception) { s_logger.Error(exception, "Notification processing failed."); } await ReleaseLeaseAsync(lease); return(result); }); s_logger.Information("Pending notifications chaser started."); }