コード例 #1
0
        public void CleanupReportRequests(IReportRequestEntryService reportRequestService)
        {
            _logger.Debug("Executing cleanup of report requests queue.");
            var allEntriesForRegionAndMerchant = reportRequestService.GetAll().Where(rrc => IsMatchForRegionAndMerchantId(rrc));
            var entriesToDelete = new List <EntryToDelete>();

            void DeleteUniqueEntries(IEnumerable <EntryToDelete> entries)
            {
                foreach (var entryToDelete in entries)
                {
                    if (!reportRequestService.GetAll().Any(rrc => rrc.Id == entryToDelete.Entry.Id))
                    {
                        continue;
                    }
                    reportRequestService.Delete(entryToDelete.Entry);
                    reportRequestService.SaveChanges();

                    _logger.Warn($"Report request entry {entryToDelete.Entry.EntryIdentityDescription} deleted from queue. {entryToDelete.ReportRequestEntryDeleteReason.ToString()} exceeded");
                }
            }

            entriesToDelete.AddRange(allEntriesForRegionAndMerchant.Where(IsRequestRetryCountExceeded)
                                     .Select(e => new EntryToDelete {
                Entry = e, ReportRequestEntryDeleteReason = ReportRequestFailureReasonType.ReportRequestMaxRetryCountExceeded
            }));
            entriesToDelete.AddRange(allEntriesForRegionAndMerchant.Where(IsDownloadRetryCountExceeded)
                                     .Select(e => new EntryToDelete {
                Entry = e, ReportRequestEntryDeleteReason = ReportRequestFailureReasonType.ReportDownloadMaxRetryCountExceeded
            }));
            entriesToDelete.AddRange(allEntriesForRegionAndMerchant.Where(IsProcessingRetryCountExceeded)
                                     .Select(e => new EntryToDelete {
                Entry = e, ReportRequestEntryDeleteReason = ReportRequestFailureReasonType.ReportProcessingMaxRetryCountExceeded
            }));
            entriesToDelete.AddRange(allEntriesForRegionAndMerchant.Where(IsExpirationPeriodExceeded)
                                     .Select(e => new EntryToDelete {
                Entry = e, ReportRequestEntryDeleteReason = ReportRequestFailureReasonType.ReportRequestEntryExpirationPeriodExceeded
            }));
            entriesToDelete.AddRange(allEntriesForRegionAndMerchant.Where(IsCallbackInvocationRetryCountExceeded)
                                     .Select(e => new EntryToDelete {
                Entry = e, ReportRequestEntryDeleteReason = ReportRequestFailureReasonType.InvokeCallbackMaxRetryCountExceeded
            }));

            foreach (var entryToDelete in entriesToDelete)
            {
                OnReportEntryWasMarkedForDelete(new ReportRequestFailedEventArgs(
                                                    entryToDelete.ReportRequestEntryDeleteReason,
                                                    entryToDelete.Entry.AmazonRegion,
                                                    entryToDelete.Entry.LastAmazonRequestDate,
                                                    entryToDelete.Entry.LastAmazonReportProcessingStatus,
                                                    entryToDelete.Entry.RequestReportId,
                                                    entryToDelete.Entry.GeneratedReportId,
                                                    entryToDelete.Entry.GetPropertiesContainer(),
                                                    entryToDelete.Entry.TargetHandlerId,
                                                    entryToDelete.Entry.TargetHandlerArgs,
                                                    entryToDelete.Entry.ReportType));
            }

            DeleteUniqueEntries(entriesToDelete.Distinct());
        }
コード例 #2
0
ファイル: ReportProcessor.cs プロジェクト: jdease/EasyMWS
        public void PurgeQueue(IReportRequestEntryService reportRequestService)
        {
            var entriesToDelete = reportRequestService.GetAll().Where(rre => rre.AmazonRegion == _region && rre.MerchantId == _merchantId);

            reportRequestService.DeleteRange(entriesToDelete);
            reportRequestService.SaveChanges();
        }