Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 2
0
        public async Task EnqueueManyAsync(IEnumerable <object> items, DateTime?whenToProcess)
        {
            IEnumerable <WorkQueueItem> workQueueItems =
                from item in items
                where item != null
                let obj = JObject.FromObject(item)
                          where obj != null
                          select new WorkQueueItem(item.NotNull().GetType().FullName.NotNull(), obj.NotNull(), whenToProcess ?? DateTime.Now, 0);

            await _WorkQueueRepositoryManager.EnqueueManyAsync(workQueueItems);

            await _Bus.PublishAsync(new WorkQueueItemAddedMessage());
        }