Skip to content

Commit

Permalink
fix for task update updating to same status
Browse files Browse the repository at this point in the history
Signed-off-by: Neil South <[email protected]>
  • Loading branch information
neildsouth committed May 20, 2024
1 parent 1e4ae01 commit 47f0192
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/WorkflowManager/Logging/Log.200000.Workflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions src/WorkflowManager/Logging/Log.700000.Artifact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check warning on line 64 in src/WorkflowManager/Logging/Log.700000.Artifact.cs

View workflow job for this annotation

GitHub Actions / sonarscanner

Remove this commented out code. (https://rules.sonarsource.com/csharp/RSPEC-125)

[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);


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ private Dictionary<ArtifactType, bool> 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
{
Expand Down Expand Up @@ -481,6 +481,12 @@ public async Task<bool> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3977,6 +3977,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<WorkflowRevision>
{
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<string>(), It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(() => "lordge");

_workflowRepository.Setup(w => w.GetWorkflowsByAeTitleAsync(It.IsAny<List<string>>())).ReturnsAsync(workflows);
_workflowRepository.Setup(w => w.GetWorkflowsForWorkflowRequestAsync(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(workflows);
_workflowRepository.Setup(w => w.GetByWorkflowIdAsync(workflows[0].WorkflowId)).ReturnsAsync(workflows[0]);
_workflowInstanceRepository.Setup(w => w.CreateAsync(It.IsAny<List<WorkflowInstance>>())).ReturnsAsync(true);
_workflowInstanceRepository.Setup(w => w.GetByWorkflowsIdsAsync(It.IsAny<List<string>>())).ReturnsAsync(new List<WorkflowInstance>());
_workflowInstanceRepository.Setup(w => w.UpdateTaskStatusAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<TaskExecutionStatus>())).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<Message>()), Times.Once());

Assert.True(result);
}
}
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
}

0 comments on commit 47f0192

Please sign in to comment.