Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
 private ProcessingContext(ProcessingContext other)
 {
     Provider          = other.Provider;
     CancellationToken = other.CancellationToken;
 }
Ejemplo n.º 5
0
 protected virtual CancellationToken GetTokenToWaitOn(ProcessingContext context)
 {
     return(context.CancellationToken);
 }