public async Task ProcessAsync(ProcessingContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } context.ThrowIfStopping(); _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); }
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 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); } }
private ProcessingContext(ProcessingContext other) { Provider = other.Provider; CancellationToken = other.CancellationToken; }
protected virtual CancellationToken GetTokenToWaitOn(ProcessingContext context) { return(context.CancellationToken); }