/// <summary> /// Requeues the orphaned processing items. /// If any ReportStatusId == 2 and the ReportGenerationQueueId is not in the list /// of threads that is executing the reports anymore, then 'RESET' the item, for regeneration /// increase the retry count /// </summary> /// <param name="generationDao">The generation DAO.</param> private void RequeueOrphanedProcessingItems(GenerationDao generationDao) { List<ReportGenerationQueue> processingReportList = generationDao.FindAll<ReportGenerationQueue>(queue => queue.ReportGenerationStatus == ReportStatus.Processing).ToList(); if (processingReportList != null && processingReportList.Count > 0) { foreach (ReportGenerationQueue item in processingReportList) { IHostedProcess runningApplication = this._reportGeneratorEngineList.FirstOrDefault( entity => entity.ReportGenerationQueueId == item.ReportGenerationQueueId); if (runningApplication == null) { // this item in set to running in DB, but is not in current executing threads anymore // hence this might be a report that generated a fatal exception, that can be recovered & rescheduled this.ReportQueueStatusService.UpdateReportGenerationQueue(new ReportGenerationQueueStatusDto() { ReportGenerationQueueId = item.ReportGenerationQueueId, NumberOfRetries = item.NumberOfRetries + 1, ReportStatus = ReportStatus.Queued }); } } } }
/// <summary> /// Pulls the next report. /// </summary> /// <param name="generationDao">The generation DAO.</param> /// <returns></returns> private ReportGenerationQueue PullNextReport(GenerationDao generationDao) { List<ReportGenerationQueue> scheduledReportList = generationDao .FindAll<ReportGenerationQueue>(queue => queue.ReportGenerationStatus == ReportStatus.Queued) .OrderBy(entity => entity.ReportGenerationQueueId) .ToList(); scheduledReportList = this.FilterQueueForUser(scheduledReportList); ReportGenerationQueue queuedReport = scheduledReportList.FirstOrDefault(); return queuedReport; }