Пример #1
0
        public async Task ProcessSynchronously(IReadOnlyCollection <IAsyncEventQueueRecord> eventsToProcess)
        {
            string[] queues = eventsToProcess.Select(x => x.QueueName).Distinct().ToArray();
            List <IAsyncEventQueueRecord> remainingEvents = eventsToProcess.ToList();

            int      triesLeft = asyncEventPipelineConfiguration.SyncProcessAttemptCount;
            TimeSpan sleepTime = asyncEventPipelineConfiguration.SyncProcessRetryTimeout;

            while (triesLeft > 0)
            {
                triesLeft--;
                queues = await TryRunQueues(queues);

                if (queues.Length == 0)
                {
                    break;
                }

                remainingEvents = (await asyncEventQueueManager.FindQueuedEventsAsync(remainingEvents.Select(x => x.Id).ToArray())).ToList();
                if (remainingEvents.Count == 0)
                {
                    break;
                }

                if (triesLeft > 0)
                {
                    await Sleep.Current.SleepAsync(sleepTime);

                    sleepTime = TimeSpan.FromTicks(sleepTime.Ticks * asyncEventPipelineConfiguration.SyncProcessRetryTimeoutMultiplier);
                }
            }

            if (queues.Length > 0 && remainingEvents.Count > 0)
            {
                Logger.Error(
                    $"Not able to synchronously process all event queues, about to reschedule {remainingEvents.Count} events for later async processing in {asyncEventPipelineConfiguration.AsyncRescheduleDelayAfterSyncProcessFailure.TotalSeconds:0.##} seconds");
                await EnqueueForAsyncProcessingAsync(remainingEvents, asyncEventPipelineConfiguration.AsyncRescheduleDelayAfterSyncProcessFailure);
            }
        }