Skip to content

Commit

Permalink
Merge pull request #797 from mrcopperbeard/master
Browse files Browse the repository at this point in the history
Set CompleteTime to WorkflowInstance when terminating workflow.
  • Loading branch information
danielgerlag authored Apr 11, 2021
2 parents 30c98f8 + b64103b commit 674929f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
10 changes: 5 additions & 5 deletions src/WorkflowCore/Models/WorkflowInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public bool IsBranchComplete(string parentId)
}
}

public enum WorkflowStatus
public enum WorkflowStatus
{
Runnable = 0,
Suspended = 1,
Complete = 2,
Terminated = 3
Runnable = 0,
Suspended = 1,
Complete = 2,
Terminated = 3,
}
}
12 changes: 7 additions & 5 deletions src/WorkflowCore/Services/ErrorHandlers/TerminateHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using WorkflowCore.Interface;
using WorkflowCore.Models;
Expand All @@ -9,21 +9,23 @@ namespace WorkflowCore.Services.ErrorHandlers
public class TerminateHandler : IWorkflowErrorHandler
{
private readonly ILifeCycleEventPublisher _eventPublisher;
private readonly IDateTimeProvider _datetimeProvider;
private readonly IDateTimeProvider _dateTimeProvider;
public WorkflowErrorHandling Type => WorkflowErrorHandling.Terminate;

public TerminateHandler(ILifeCycleEventPublisher eventPublisher, IDateTimeProvider datetimeProvider)
public TerminateHandler(ILifeCycleEventPublisher eventPublisher, IDateTimeProvider dateTimeProvider)
{
_eventPublisher = eventPublisher;
_datetimeProvider = datetimeProvider;
_dateTimeProvider = dateTimeProvider;
}

public void Handle(WorkflowInstance workflow, WorkflowDefinition def, ExecutionPointer pointer, WorkflowStep step, Exception exception, Queue<ExecutionPointer> bubbleUpQueue)
{
workflow.Status = WorkflowStatus.Terminated;
workflow.CompleteTime = _dateTimeProvider.UtcNow;

_eventPublisher.PublishNotification(new WorkflowTerminated
{
EventTimeUtc = _datetimeProvider.UtcNow,
EventTimeUtc = _dateTimeProvider.UtcNow,
Reference = workflow.Reference,
WorkflowInstanceId = workflow.Id,
WorkflowDefinitionId = workflow.WorkflowDefinitionId,
Expand Down
14 changes: 9 additions & 5 deletions src/WorkflowCore/Services/WorkflowController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using WorkflowCore.Exceptions;
Expand Down Expand Up @@ -46,10 +47,10 @@ public Task<string> StartWorkflow(string workflowId, int? version, object data =
return StartWorkflow<object>(workflowId, version, data, reference);
}

public Task<string> StartWorkflow<TData>(string workflowId, TData data = null, string reference=null)
public Task<string> StartWorkflow<TData>(string workflowId, TData data = null, string reference = null)
where TData : class, new()
{
return StartWorkflow<TData>(workflowId, null, data, reference);
return StartWorkflow(workflowId, null, data, reference);
}

public async Task<string> StartWorkflow<TData>(string workflowId, int? version, TData data = null, string reference=null)
Expand Down Expand Up @@ -203,7 +204,10 @@ public async Task<bool> TerminateWorkflow(string workflowId)
try
{
var wf = await _persistenceStore.GetWorkflowInstance(workflowId);

wf.Status = WorkflowStatus.Terminated;
wf.CompleteTime = _dateTimeProvider.UtcNow;

await _persistenceStore.PersistWorkflow(wf);
await _queueProvider.QueueWork(workflowId, QueueType.Index);
await _eventHub.PublishNotification(new WorkflowTerminated
Expand All @@ -225,16 +229,16 @@ await _eventHub.PublishNotification(new WorkflowTerminated
public void RegisterWorkflow<TWorkflow>()
where TWorkflow : IWorkflow
{
TWorkflow wf = ActivatorUtilities.CreateInstance<TWorkflow>(_serviceProvider);
var wf = ActivatorUtilities.CreateInstance<TWorkflow>(_serviceProvider);
_registry.RegisterWorkflow(wf);
}

public void RegisterWorkflow<TWorkflow, TData>()
where TWorkflow : IWorkflow<TData>
where TData : new()
{
TWorkflow wf = ActivatorUtilities.CreateInstance<TWorkflow>(_serviceProvider);
_registry.RegisterWorkflow<TData>(wf);
var wf = ActivatorUtilities.CreateInstance<TWorkflow>(_serviceProvider);
_registry.RegisterWorkflow(wf);
}
}
}
7 changes: 4 additions & 3 deletions src/WorkflowCore/Services/WorkflowExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Microsoft.Extensions.Logging;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection;
using WorkflowCore.Interface;
using WorkflowCore.Models;
Expand Down Expand Up @@ -164,7 +165,7 @@ private async Task ExecuteStep(WorkflowInstance workflow, WorkflowStep step, Exe
WorkflowId = workflow.Id,
ExecutionPointerId = pointer.Id,
ErrorTime = _datetimeProvider.UtcNow,
Message = $"Unable to construct step body {step.BodyType.ToString()}"
Message = $"Unable to construct step body {step.BodyType}"
});
return;
}
Expand Down

0 comments on commit 674929f

Please sign in to comment.