diff --git a/src/WorkflowManager/Logging/Log.200000.Workflow.cs b/src/WorkflowManager/Logging/Log.200000.Workflow.cs index 62527c0cc..d42d8cddb 100644 --- a/src/WorkflowManager/Logging/Log.200000.Workflow.cs +++ b/src/WorkflowManager/Logging/Log.200000.Workflow.cs @@ -84,6 +84,9 @@ public static partial class Log [LoggerMessage(EventId = 200020, Level = LogLevel.Warning, Message = "Use new ArtifactReceived Queue for continuation messages.")] public static partial void DontUseWorkflowReceivedForPayload(this ILogger logger); + [LoggerMessage(EventId = 200021, Level = LogLevel.Trace, Message = "The task execution status for task {taskId} is already {status}. Payload: {payloadId}")] + public static partial void TaskStatusUpdateNotNeeded(this ILogger logger, string payloadId, string taskId, string status); + // Conditions Resolver [LoggerMessage(EventId = 210000, Level = LogLevel.Warning, Message = "Failed to parse condition: {condition}. resolvedConditional: {resolvedConditional}")] public static partial void FailedToParseCondition(this ILogger logger, string resolvedConditional, string condition, Exception ex); diff --git a/src/WorkflowManager/Logging/Log.700000.Artifact.cs b/src/WorkflowManager/Logging/Log.700000.Artifact.cs index 246e14f2d..b90d6d1f3 100644 --- a/src/WorkflowManager/Logging/Log.700000.Artifact.cs +++ b/src/WorkflowManager/Logging/Log.700000.Artifact.cs @@ -60,12 +60,15 @@ public static partial class Log [LoggerMessage(EventId = 700012, Level = LogLevel.Error, Message = "Error finding Task :{taskId}")] public static partial void ErrorFindingTask(this ILogger logger, string taskId); - [LoggerMessage(EventId = 700013, Level = LogLevel.Error, Message = "Error finding Task :{taskId} or previousTask {previousTask}")] - public static partial void ErrorFindingTaskOrPrevious(this ILogger logger, string taskId, string previousTask); + //[LoggerMessage(EventId = 700013, Level = LogLevel.Error, Message = "Error finding Task :{taskId} or previousTask {previousTask}")] + //public static partial void ErrorFindingTaskOrPrevious(this ILogger logger, string taskId, string previousTask); [LoggerMessage(EventId = 700014, Level = LogLevel.Warning, Message = "Error Task :{taskId} cant be trigger as it has missing artifacts {missingtypesJson}")] public static partial void ErrorTaskMissingArtifacts(this ILogger logger, string taskId, string missingtypesJson); + [LoggerMessage(EventId = 700015, Level = LogLevel.Warning, Message = "Error Task :{taskId} cant be trigger as it has missing artifacts {artifactName}")] + public static partial void ErrorFindingArtifactInPrevious(this ILogger logger, string taskId, string artifactName); + } } diff --git a/src/WorkflowManager/WorkflowExecuter/Services/WorkflowExecuterService.cs b/src/WorkflowManager/WorkflowExecuter/Services/WorkflowExecuterService.cs index 361cdddae..7ca2a1cec 100644 --- a/src/WorkflowManager/WorkflowExecuter/Services/WorkflowExecuterService.cs +++ b/src/WorkflowManager/WorkflowExecuter/Services/WorkflowExecuterService.cs @@ -376,7 +376,7 @@ private Dictionary GetTasksInput(WorkflowRevision workflowTe var matchType = previousTask.Artifacts.Output.FirstOrDefault(t => t.Name == artifact.Name); if (matchType is null) { - _logger.ErrorFindingTaskOrPrevious(taskId, previousTaskId); + _logger.ErrorFindingArtifactInPrevious(taskId, artifact.Name); } else { @@ -481,6 +481,12 @@ public async Task ProcessTaskUpdate(TaskUpdateEvent message) await ClinicalReviewTimeOutEvent(workflowInstance, currentTask, message.CorrelationId); } + if (message.Status == currentTask.Status) + { + _logger.TaskStatusUpdateNotNeeded(workflowInstance.PayloadId, message.TaskId, message.Status.ToString()); + return true; + } + if (!message.Status.IsTaskExecutionStatusUpdateValid(currentTask.Status)) { _logger.TaskStatusUpdateNotValid(workflowInstance.PayloadId, message.TaskId, currentTask.Status.ToString(), message.Status.ToString()); diff --git a/tests/UnitTests/WorkflowExecuter.Tests/Services/WorkflowExecuterServiceTests.cs b/tests/UnitTests/WorkflowExecuter.Tests/Services/WorkflowExecuterServiceTests.cs index c6697ccb5..966404893 100755 --- a/tests/UnitTests/WorkflowExecuter.Tests/Services/WorkflowExecuterServiceTests.cs +++ b/tests/UnitTests/WorkflowExecuter.Tests/Services/WorkflowExecuterServiceTests.cs @@ -3702,6 +3702,88 @@ public async Task ProcessTaskUpdate_ValidTaskUpdateEventWithExportHl7TaskDestina response.Should().BeTrue(); } + [Fact] + public async Task ProcessTaskUpdate_ValidTaskUpdateEventWith_Same_Status_returns_true() + { + var workflowInstanceId = Guid.NewGuid().ToString(); + var taskId = Guid.NewGuid().ToString(); + + var updateEvent = new TaskUpdateEvent + { + WorkflowInstanceId = workflowInstanceId, + TaskId = "pizza", + ExecutionId = Guid.NewGuid().ToString(), + Status = TaskExecutionStatus.Succeeded, + }; + + var workflowId = Guid.NewGuid().ToString(); + + var workflow = new WorkflowRevision + { + Id = Guid.NewGuid().ToString(), + WorkflowId = workflowId, + Revision = 1, + Workflow = new Workflow + { + Name = "Workflowname2", + Description = "Workflowdesc2", + Version = "1", + InformaticsGateway = new InformaticsGateway + { + AeTitle = "aetitle" + }, + Tasks = new TaskObject[] + { + new TaskObject { + Id = "pizza", + Type = "type", + Description = "taskdesc", + TaskDestinations = new TaskDestination[] + { + new TaskDestination + { + Name = "exporttaskid" + }, + } + } + } + } + }; + + var workflowInstance = new WorkflowInstance + { + Id = workflowInstanceId, + WorkflowId = workflowId, + WorkflowName = workflow.Workflow.Name, + PayloadId = Guid.NewGuid().ToString(), + Status = Status.Created, + BucketId = "bucket", + Tasks = new List + { + new TaskExecution + { + TaskId = "pizza", + Status = TaskExecutionStatus.Succeeded + } + } + }; + + _workflowInstanceRepository.Setup(w => w.UpdateTaskStatusAsync(It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(true); + _workflowInstanceRepository.Setup(w => w.GetByWorkflowInstanceIdAsync(workflowInstance.Id)).ReturnsAsync(workflowInstance); + _workflowInstanceRepository.Setup(w => w.UpdateTasksAsync(workflowInstance.Id, It.IsAny>())).ReturnsAsync(true); + _workflowRepository.Setup(w => w.GetByWorkflowIdAsync(workflowInstance.WorkflowId)).ReturnsAsync(workflow); + _payloadService.Setup(p => p.GetByIdAsync(It.IsAny())).ReturnsAsync(new Payload { PatientDetails = new PatientDetails { } }); + _artifactMapper.Setup(a => a.ConvertArtifactVariablesToPath(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(new Dictionary { { "dicomexport", "/dcm" } }); + + var response = await WorkflowExecuterService.ProcessTaskUpdate(updateEvent); + + _messageBrokerPublisherService.Verify(w => w.Publish(_configuration.Value.Messaging.Topics.ExportHL7, It.IsAny()), Times.Exactly(0)); + + _logger.Verify(logger => logger.IsEnabled(LogLevel.Trace),Times.Once); + + response.Should().BeTrue(); + } + [Fact] public async Task ProcessPayload_With_Multiple_Taskdestinations_One_Has_Inputs() { @@ -3977,6 +4059,62 @@ public async Task ProcessPayload_With_Passing_Workflow_Conditional_Should_Procce Assert.True(result); } + + [Fact] + public async Task ProcessPayload_With_Empty_Workflow_Conditional_Should_Procced() + { + var workflowRequest = new WorkflowRequestEvent + { + Bucket = "testbucket", + DataTrigger = new DataOrigin { Source = "aetitle", Destination = "aetitle" }, + CorrelationId = Guid.NewGuid().ToString(), + Timestamp = DateTime.UtcNow + }; + + var workflows = new List + { + new() { + Id = Guid.NewGuid().ToString(), + WorkflowId = Guid.NewGuid().ToString(), + Revision = 1, + Workflow = new Workflow + { + Name = "Workflowname", + Description = "Workflowdesc", + Version = "1", + InformaticsGateway = new InformaticsGateway + { + AeTitle = "aetitle" + }, + Tasks = + [ + new TaskObject { + Id = Guid.NewGuid().ToString(), + Type = "type", + Description = "taskdesc" + } + ], + Predicate = [] + } + } + }; + + _dicom.Setup(w => w.GetAnyValueAsync(It.IsAny(), It.IsAny(), It.IsAny())) + .ReturnsAsync(() => "lordge"); + + _workflowRepository.Setup(w => w.GetWorkflowsByAeTitleAsync(It.IsAny>())).ReturnsAsync(workflows); + _workflowRepository.Setup(w => w.GetWorkflowsForWorkflowRequestAsync(It.IsAny(), It.IsAny())).ReturnsAsync(workflows); + _workflowRepository.Setup(w => w.GetByWorkflowIdAsync(workflows[0].WorkflowId)).ReturnsAsync(workflows[0]); + _workflowInstanceRepository.Setup(w => w.CreateAsync(It.IsAny>())).ReturnsAsync(true); + _workflowInstanceRepository.Setup(w => w.GetByWorkflowsIdsAsync(It.IsAny>())).ReturnsAsync(new List()); + _workflowInstanceRepository.Setup(w => w.UpdateTaskStatusAsync(It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(true); + + var result = await WorkflowExecuterService.ProcessPayload(workflowRequest, new Payload() { Id = Guid.NewGuid().ToString() }); + + _messageBrokerPublisherService.Verify(w => w.Publish(_configuration.Value.Messaging.Topics.TaskDispatchRequest, It.IsAny()), Times.Once()); + + Assert.True(result); + } } #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. }