public async Task ProcessAsync(ProcessingContext context) { var tables = new[] { _initializer.GetPublishedTableName(), _initializer.GetReceivedTableName() }; foreach (var table in tables) { _logger.LogDebug($"Collecting expired data from table: {table}"); int deletedCount; var time = DateTime.Now; do { deletedCount = await _storage.DeleteExpiresAsync(table, time, ItemBatch, context.CancellationToken); if (deletedCount != 0) { await context.WaitAsync(_delay); context.ThrowIfStopping(); } } while (deletedCount != 0); } await context.WaitAsync(_waitingInterval); }
private async Task ProcessReceivedAsync(IStorageConnection connection, ProcessingContext context) { var messages = await connection.GetReceivedMessagesOfNeedRetry(); var hasException = false; foreach (var message in messages) { if (message.Retries > _options.FailedRetryCount) { continue; } if (!hasException) { try { _options.FailedCallback?.Invoke(MessageType.Subscribe, message.Name, message.Content); } catch (Exception ex) { hasException = true; _logger.LogWarning("Failed call-back method raised an exception:" + ex.Message); } } await _subscriberExecutor.ExecuteAsync(message); context.ThrowIfStopping(); await context.WaitAsync(_delay); } }
private async Task ProcessReceivededAsync(IStorageConnection connection, ProcessingContext context) { var messages = await connection.GetFailedReceviedMessages(); var hasException = false; foreach (var message in messages) { if (!hasException) { try { _options.FailedCallback?.Invoke(Models.MessageType.Subscribe, message.Name, message.Content); } catch (Exception ex) { hasException = true; _logger.LogWarning("Failed call-back method raised an exception:" + ex.Message); } } using (var transaction = connection.CreateTransaction()) { _stateChanger.ChangeState(message, new EnqueuedState(), transaction); await transaction.CommitAsync(); } context.ThrowIfStopping(); await context.WaitAsync(_delay); } }
private async Task ProcessPublishedAsync(IStorageConnection connection, ProcessingContext context) { var messages = await GetSafelyAsync(connection.GetPublishedMessagesOfNeedRetry); foreach (var message in messages) { await _publishMessageSender.SendAsync(message); await context.WaitAsync(_delay); } }
private async Task ProcessReceivedAsync(IStorageConnection connection, ProcessingContext context) { context.ThrowIfStopping(); var messages = await GetSafelyAsync(connection.GetReceivedMessagesOfNeedRetry); foreach (var message in messages) { await _subscriberExecutor.ExecuteAsync(message); await context.WaitAsync(_delay); } }
public async Task ProcessAsync(ProcessingContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var connection = context.Provider.GetRequiredService <IStorageConnection>(); await Task.WhenAll(ProcessPublishedAsync(connection, context), ProcessReceivedAsync(connection, context)); await context.WaitAsync(_waitingInterval); }
private async Task ProcessReceivedAsync(IDataStorage connection, ProcessingContext context) { context.ThrowIfStopping(); var messages = await GetSafelyAsync(connection.GetReceivedMessagesOfNeedRetry); foreach (var message in messages) { await _subscribeDispatcher.DispatchAsync(message, context.CancellationToken); await context.WaitAsync(_delay); } }
private async Task ProcessPublishedAsync(IDataStorage connection, ProcessingContext context) { context.ThrowIfStopping(); var messages = await GetSafelyAsync(connection.GetPublishedMessagesOfNeedRetry); foreach (var message in messages) { await _messageSender.SendAsync(message); await context.WaitAsync(_delay); } }
public async Task ProcessAsync(ProcessingContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (!_register.IsHealthy()) { _register.ReStart(); } await context.WaitAsync(_waitingInterval); }
public async Task ProcessAsync(ProcessingContext context) { foreach (var table in _tableNames) { _logger.LogDebug($"Collecting expired data from table: {table}"); int deletedCount; var time = DateTime.Now; do { deletedCount = await _serviceProvider.GetService <IDataStorage>() .DeleteExpiresAsync(table, time, ItemBatch, context.CancellationToken); if (deletedCount != 0) { await context.WaitAsync(_delay); context.ThrowIfStopping(); } } while (deletedCount != 0); } await context.WaitAsync(_waitingInterval); }
private async Task ProcessReceivededAsync(IStorageConnection connection, ProcessingContext context) { var messages = await connection.GetFailedReceviedMessages(); foreach (var message in messages) { using (var transaction = connection.CreateTransaction()) { _stateChanger.ChangeState(message, new EnqueuedState(), transaction); await transaction.CommitAsync(); } context.ThrowIfStopping(); await context.WaitAsync(_delay); } }
private async Task ProcessPublishedAsync(IStorageConnection connection, ProcessingContext context) { var messages = await connection.GetPublishedMessagesOfNeedRetry(); var hasException = false; foreach (var message in messages) { if (message.Retries > _options.FailedRetryCount) { continue; } if (!hasException) { try { _options.FailedCallback?.Invoke(MessageType.Publish, message.Name, message.Content); } catch (Exception ex) { hasException = true; _logger.LogWarning("Failed call-back method raised an exception:" + ex.Message); } } using (var transaction = connection.CreateTransaction()) { try { await _publishExecutor.PublishAsync(message.Name, message.Content); _stateChanger.ChangeState(message, new SucceededState(), transaction); } catch (Exception e) { message.Content = Helper.AddExceptionProperty(message.Content, e); transaction.UpdateMessage(message); } await transaction.CommitAsync(); } context.ThrowIfStopping(); await context.WaitAsync(_delay); } }
public async Task ProcessAsync(ProcessingContext context) { while (!context.IsStopping) { try { await _inner.ProcessAsync(context); } catch (OperationCanceledException) { //ignore } catch (Exception ex) { _logger.LogWarning(ex, "Processor '{ProcessorName}' failed. Retrying...", _inner.ToString()); await context.WaitAsync(TimeSpan.FromSeconds(2)); } } }
public async Task ProcessAsync(ProcessingContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } using (var scope = _provider.CreateScope()) { var provider = scope.ServiceProvider; var connection = provider.GetRequiredService <IStorageConnection>(); await Task.WhenAll( ProcessPublishedAsync(connection, context), ProcessReceivedAsync(connection, context)); await context.WaitAsync(_waitingInterval); } }
public async Task ProcessAsync(ProcessingContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } _logger.LogDebug("Transport connection checking..."); if (!_register.IsHealthy()) { _logger.LogWarning("Transport connection is unhealthy, reconnection..."); _register.ReStart(); } else { _logger.LogDebug("Transport connection healthy!"); } await context.WaitAsync(_waitingInterval); }
private async Task ProcessPublishedAsync(IStorageConnection connection, ProcessingContext context) { var messages = await connection.GetPublishedMessagesOfNeedRetry(); var hasException = false; foreach (var message in messages) { if (message.Retries > _options.FailedRetryCount) { continue; } using (var transaction = connection.CreateTransaction()) { var result = await _publishExecutor.PublishAsync(message.Name, message.Content); if (result.Succeeded) { _stateChanger.ChangeState(message, new SucceededState(), transaction); _logger.LogInformation("The message was sent successfully during the retry. MessageId:" + message.Id); } else { message.Content = Helper.AddExceptionProperty(message.Content, result.Exception); message.Retries++; if (message.StatusName == StatusName.Scheduled) { message.ExpiresAt = GetDueTime(message.Added, message.Retries); message.StatusName = StatusName.Failed; } transaction.UpdateMessage(message); if (message.Retries >= _options.FailedRetryCount) { _logger.LogError($"The message still sent failed after {_options.FailedRetryCount} retries. We will stop retrying the message. " + "MessageId:" + message.Id); if (message.Retries == _options.FailedRetryCount) { if (!hasException) { try { _options.FailedThresholdCallback?.Invoke(MessageType.Publish, message.Name, message.Content); } catch (Exception ex) { hasException = true; _logger.LogWarning("Failed call-back method raised an exception:" + ex.Message); } } } } } await transaction.CommitAsync(); } context.ThrowIfStopping(); await context.WaitAsync(_delay); } }