예제 #1
0
        private async Task Process <T>(WorkQueueItem item, CancellationToken cancellationToken)
            where T : class
        {
            T   payload   = item.Payload.ToObject <T>().NotNull();
            var processor = _Container.Resolve <IWorkQueueProcessor <T> >(IfUnresolved.ReturnDefaultIfNotRegistered);

            if (processor == null)
            {
                _Logger.LogError($"work queue item '{item.Type}' has no processor, item faulted");
                await _WorkQueueRepositoryManager.FaultedAsync(item);

                return;
            }

            using (_Logger.LogScope(LogLevel.Verbose, $"processing work queue item '{item.Type}'"))
            {
                try
                {
                    await processor.Process(payload, cancellationToken);
                }
                catch (TaskCanceledException)
                {
                    await _WorkQueueRepositoryManager.EnqueueManyAsync(new[] { item });

                    throw;
                }
                catch (Exception ex)
                {
                    _Logger.LogException(ex);
                    await _WorkQueueRepositoryManager.RetryAsync(item);
                }
            }
        }
예제 #2
0
        public async Task RetryAsync(WorkQueueItem item)
        {
            int      retryCount  = item.RetryCount + 1;
            DateTime?whenToRetry = _RetryPolicy.WhenToRetry(retryCount);

            if (whenToRetry == null)
            {
                _Logger.LogError($"work queue item '{item.Type}' retried too many times, item now faulted");
                await FaultedAsync(item);

                return;
            }

            await EnqueueManyAsync(new[] { new WorkQueueItem(item.Type, item.Payload, whenToRetry.Value, retryCount) });
        }
예제 #3
0
 public Task FaultedAsync(WorkQueueItem item) => GetEnabledRepository()?.FaultedAsync(item) ?? Task.CompletedTask;