Skip to content

Commit

Permalink
Fixed issue where updated and finished date where not set when cancel…
Browse files Browse the repository at this point in the history
…ling a workflow
  • Loading branch information
raymonddenhaan committed Feb 16, 2024
1 parent ef3431c commit f0b5f75
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public partial class WorkflowExecutionContext : IExecutionContext
ExecuteDelegate = executeDelegate;
TriggerActivityId = triggerActivityId;
CreatedAt = createdAt;
UpdatedAt = createdAt;
CancellationTokens = cancellationTokens;
Incidents = incidents.ToList();

Expand Down Expand Up @@ -275,7 +276,12 @@ public async Task SetWorkflowAsync(Workflow workflow)
/// The date and time the workflow execution context was created.
/// </summary>
public DateTimeOffset CreatedAt { get; set; }


/// <summary>
/// The date and time the workflow execution context was last updated.
/// </summary>
public DateTimeOffset UpdatedAt { get; set; }

/// <summary>
/// The date and time the workflow execution context has finished.
/// </summary>
Expand Down Expand Up @@ -539,7 +545,11 @@ internal void TransitionTo(WorkflowSubStatus subStatus)
throw new Exception($"Cannot transition from {SubStatus} to {subStatus}");

SubStatus = subStatus;

UpdatedAt = SystemClock.UtcNow;

if (Status == WorkflowStatus.Finished)
FinishedAt = UpdatedAt;

//For now only trigger on Cancelled, since the other statuses are handling via the host/runner
if (SubStatus == WorkflowSubStatus.Cancelled
&& _statusUpdatedCallback is not null)
Expand Down
2 changes: 0 additions & 2 deletions src/modules/Elsa.Workflows.Core/Services/WorkflowRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,9 @@ public async Task<RunWorkflowResult> RunAsync(WorkflowExecutionContext workflowE

await _pipeline.ExecuteAsync(workflowExecutionContext);
var workflowState = _workflowStateExtractor.Extract(workflowExecutionContext);
workflowState.UpdatedAt = _systemClock.UtcNow;

if (workflowState.Status == WorkflowStatus.Finished)
{
workflowState.FinishedAt = workflowState.UpdatedAt;
await _notificationSender.SendAsync(new WorkflowFinished(workflow, workflowState, workflowExecutionContext), applicationCancellationToken);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public WorkflowState Extract(WorkflowExecutionContext workflowExecutionContext)
Input = GetPersistableInput(workflowExecutionContext),
Output = workflowExecutionContext.Output,
Incidents = workflowExecutionContext.Incidents,
CreatedAt = workflowExecutionContext.CreatedAt
CreatedAt = workflowExecutionContext.CreatedAt,
UpdatedAt = workflowExecutionContext.UpdatedAt,
FinishedAt = workflowExecutionContext.FinishedAt
};

ExtractProperties(state, workflowExecutionContext);
Expand All @@ -46,6 +48,8 @@ public WorkflowExecutionContext Apply(WorkflowExecutionContext workflowExecution
workflowExecutionContext.Output = state.Output;
workflowExecutionContext.ExecutionLogSequence = state.ExecutionLogSequence;
workflowExecutionContext.CreatedAt = state.CreatedAt;
workflowExecutionContext.UpdatedAt = state.UpdatedAt;
workflowExecutionContext.FinishedAt = state.FinishedAt;
ApplyInput(state, workflowExecutionContext);
ApplyProperties(state, workflowExecutionContext);
ApplyActivityExecutionContexts(state, workflowExecutionContext);
Expand Down

0 comments on commit f0b5f75

Please sign in to comment.