public async Task Execute(CancellationToken cancellationToken, RecommendationsReportGenerationJobParameters input) { var recommendations = _recommendationRepository .GetByScenarioId(input.ScenarioId) .ToArray(); if (!recommendations.Any()) { status = ReportExportStatus.GenerationFailed; _cache.Set(input.ReportReference, status, CreatePreCompletionCachePolicy()); var message = $"No recommendations are available for the specified scenario ID. ({input.ScenarioId})"; _exportStatusNotifier.NotifyGroup(new ReportExportStatusNotification { reportReference = input.ReportReference, status = status, message = message }); LogError(new ArgumentException(message), message); return; } Stream reportStream = null; try { status = ReportExportStatus.Generating; _cache.Set(input.ReportReference, status, CreatePreCompletionCachePolicy()); _exportStatusNotifier.NotifyGroup(new ReportExportStatusNotification { reportReference = input.ReportReference, status = status }); reportStream = _recommendationsResultReportCreator.GenerateReport(recommendations); } catch (Exception exception) { status = ReportExportStatus.GenerationFailed; _cache.Set(input.ReportReference, status, CreatePreCompletionCachePolicy()); _exportStatusNotifier.NotifyGroup(new ReportExportStatusNotification { reportReference = input.ReportReference, status = status }); LogError(exception, $"Something went wrong while generating a recommendation report for scenario with ID '{input.ScenarioId}'."); reportStream.Dispose(); return; } using (reportStream) { try { status = ReportExportStatus.Uploading; _cache.Set(input.ReportReference, status, CreatePreCompletionCachePolicy()); _exportStatusNotifier.NotifyGroup(new ReportExportStatusNotification { reportReference = input.ReportReference, status = status }); var engine = _storageClientFactory.GetEngine(); engine.Upload(new S3UploadComment() { BucketName = _awsSettings.S3Bucket, DestinationFilePath = input.FilePath, FileStream = reportStream }); } catch (Exception exception) { status = ReportExportStatus.UploadFailed; _cache.Set(input.ReportReference, status, CreatePreCompletionCachePolicy()); _exportStatusNotifier.NotifyGroup(new ReportExportStatusNotification { reportReference = input.ReportReference, status = status }); LogError(exception, $"Something went wrong while uploading the recommendation report for scenario with ID '{input.ScenarioId}'."); return; } } status = ReportExportStatus.Available; _cache.Set(input.ReportReference, status, new CacheItemPolicy { AbsoluteExpiration = DateTime.Now.AddMinutes(5) }); _exportStatusNotifier.NotifyGroup(new ReportExportStatusNotification { reportReference = input.ReportReference, status = status }); }
public IEnumerable <Transaction> GetTransactionsByUserDatesAndStatus(Guid createdby, DateTime fromDate, DateTime toDate, ReportExportStatus exportStatus) { if (exportStatus != ReportExportStatus.None) { return(GetAll(s => s.Where($" {nameof(Transaction.TransactionStatusId):C} = 8 AND {nameof(Transaction.CreatedBy):C} = @Createdby AND {nameof(Transaction.CreatedUtc):C} >= @FromDate AND {nameof(Transaction.CreatedUtc):C} <= @ToDate AND {nameof(Transaction.ReportExportStatus):C} = @ExportStatus") .WithParameters(new { CreatedBy = createdby, FromDate = fromDate, ToDate = toDate, ExportStatus = exportStatus }) )); } else { return(GetAll(s => s.Where($" {nameof(Transaction.TransactionStatusId):C} = 8 AND {nameof(Transaction.CreatedBy):C} = @Createdby AND {nameof(Transaction.CreatedUtc):C} >= @FromDate AND {nameof(Transaction.CreatedUtc):C} <= @ToDate") .WithParameters(new { CreatedBy = createdby, FromDate = fromDate, ToDate = toDate, ExportStatus = exportStatus }) )); } }