protected override Task <OutputJob> ExportDataBlockCallback(OutputJob outputJob, CancellationToken cancellationToken)
        {
            if (ExportDataBlockCalled != null)
            {
                ExportDataBlockCalled(this, new EventArgs());
            }

            if (ExportReturnsNull || outputJob is null)
            {
                return(null);
            }

            outputJob.SuccessfulExport++;
            return(Task.FromResult(outputJob));
        }
        public void ReportStatus_ShallReportFailureWithRetry()
        {
            var task = new TaskResponse
            {
                TaskId = Guid.NewGuid(),
                Uris   = new[] { "file1", "file2", "file3" }
            };

            _config.AeTitle = "AET";
            _config.HostIp  = "IP";
            _config.Port    = 1000;
            var job = new OutputJob(task, _logger.Object, _resultsService.Object, _config);

            job.ReportStatus(_cancellationTokenSource.Token);

            _resultsService.Verify(p => p.ReportFailure(task.TaskId, true, _cancellationTokenSource.Token), Times.Once());
            _resultsService.Verify(p => p.ReportSuccess(It.IsAny <Guid>(), It.IsAny <CancellationToken>()), Times.Never());
            _logger.VerifyLoggingMessageBeginsWith($"Task marked as failed with failure rate", LogLevel.Information, Times.Once());
        }
Example #3
0
        private async void QueryForTasks(ActionBlock <OutputJob> actionBlockQueue, CancellationToken cancellationToken)
        {
            var tasks = await _resultsService.GetPendingJobs(cancellationToken, 10);

            if (tasks == null || tasks.Count == 0)
            {
                return;
            }
            _logger.LogInformation("Found {0} tasks from Results Service...", tasks.Count);

            var       invalidTasks = new List <TaskResponse>();
            OutputJob outputJob    = null;

            foreach (var task in tasks)
            {
                try
                {
                    outputJob = CreateOutputJobFromTask(task);
                }
                catch (System.Exception ex)
                {
                    _logger.LogError("Error creating export task for {0}: {1}", task.TaskId, ex);
                    invalidTasks.Add(task);
                    continue;
                }

                try
                {
                    actionBlockQueue.Post(outputJob);
                    _logger.LogInformation("Export task {0} queued", task.TaskId);
                }
                catch (System.Exception ex)
                {
                    _logger.LogError("Error queueing task {0}: {1}", outputJob.TaskId, ex);
                    //do nothing, will try again on next query.
                }
            }

            if (invalidTasks.Any())
            {
                ReportFailures(invalidTasks, cancellationToken);
            }
        }
        public void LogFailedRequests_ShallLogAllFailrus()
        {
            var task = new TaskResponse();

            _config.AeTitle = "AET";
            _config.HostIp  = "IP";
            _config.Port    = 1000;
            var job = new OutputJob(task, _logger.Object, _resultsService.Object, _config);

            job.FailedFiles.Add("FILE1");

            var dicomFile = new DicomFile();

            dicomFile.FileMetaInfo.MediaStorageSOPInstanceUID = DicomUIDGenerator.GenerateDerivedFromUUID();
            job.FailedDicomFiles.Add(dicomFile, "STATUS");

            job.LogFailedRequests();

            _logger.VerifyLogging("File FILE1 failed to download, corrupted or invalid", LogLevel.Error, Times.Once());
            _logger.VerifyLogging($"C-STORE failed on {dicomFile.FileMetaInfo.MediaStorageSOPInstanceUID} with response status STATUS", LogLevel.Error, Times.Once());
        }
        public void ReportStatus_ShallReportSuccess()
        {
            var task = new TaskResponse
            {
                TaskId  = Guid.NewGuid(),
                Uris    = new[] { "file1", "file2", "file3" },
                Retries = 3
            };

            _config.AeTitle = "AET";
            _config.HostIp  = "IP";
            _config.Port    = 1000;

            var job = new OutputJob(task, _logger.Object, _resultsService.Object, _config);

            job.ProcessedDicomFiles.Add(new DicomFile());
            job.ProcessedDicomFiles.Add(new DicomFile());
            job.ReportStatus(_cancellationTokenSource.Token);

            _resultsService.Verify(p => p.ReportFailure(It.IsAny <Guid>(), It.IsAny <bool>(), It.IsAny <CancellationToken>()), Times.Never());
            _resultsService.Verify(p => p.ReportSuccess(task.TaskId, _cancellationTokenSource.Token), Times.Once());
            _logger.VerifyLogging($"Task marked as successful", LogLevel.Information, Times.Once());
        }