Skip to content

Commit 674929f

Browse files
authored
Merge pull request #797 from mrcopperbeard/master
Set CompleteTime to WorkflowInstance when terminating workflow.
2 parents 30c98f8 + b64103b commit 674929f

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

src/WorkflowCore/Models/WorkflowInstance.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ public bool IsBranchComplete(string parentId)
3535
}
3636
}
3737

38-
public enum WorkflowStatus
38+
public enum WorkflowStatus
3939
{
40-
Runnable = 0,
41-
Suspended = 1,
42-
Complete = 2,
43-
Terminated = 3
40+
Runnable = 0,
41+
Suspended = 1,
42+
Complete = 2,
43+
Terminated = 3,
4444
}
4545
}

src/WorkflowCore/Services/ErrorHandlers/TerminateHandler.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using WorkflowCore.Interface;
44
using WorkflowCore.Models;
@@ -9,21 +9,23 @@ namespace WorkflowCore.Services.ErrorHandlers
99
public class TerminateHandler : IWorkflowErrorHandler
1010
{
1111
private readonly ILifeCycleEventPublisher _eventPublisher;
12-
private readonly IDateTimeProvider _datetimeProvider;
12+
private readonly IDateTimeProvider _dateTimeProvider;
1313
public WorkflowErrorHandling Type => WorkflowErrorHandling.Terminate;
1414

15-
public TerminateHandler(ILifeCycleEventPublisher eventPublisher, IDateTimeProvider datetimeProvider)
15+
public TerminateHandler(ILifeCycleEventPublisher eventPublisher, IDateTimeProvider dateTimeProvider)
1616
{
1717
_eventPublisher = eventPublisher;
18-
_datetimeProvider = datetimeProvider;
18+
_dateTimeProvider = dateTimeProvider;
1919
}
2020

2121
public void Handle(WorkflowInstance workflow, WorkflowDefinition def, ExecutionPointer pointer, WorkflowStep step, Exception exception, Queue<ExecutionPointer> bubbleUpQueue)
2222
{
2323
workflow.Status = WorkflowStatus.Terminated;
24+
workflow.CompleteTime = _dateTimeProvider.UtcNow;
25+
2426
_eventPublisher.PublishNotification(new WorkflowTerminated
2527
{
26-
EventTimeUtc = _datetimeProvider.UtcNow,
28+
EventTimeUtc = _dateTimeProvider.UtcNow,
2729
Reference = workflow.Reference,
2830
WorkflowInstanceId = workflow.Id,
2931
WorkflowDefinitionId = workflow.WorkflowDefinitionId,

src/WorkflowCore/Services/WorkflowController.cs

+9-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using System.Threading;
44
using System.Threading.Tasks;
5+
56
using Microsoft.Extensions.DependencyInjection;
67
using Microsoft.Extensions.Logging;
78
using WorkflowCore.Exceptions;
@@ -46,10 +47,10 @@ public Task<string> StartWorkflow(string workflowId, int? version, object data =
4647
return StartWorkflow<object>(workflowId, version, data, reference);
4748
}
4849

49-
public Task<string> StartWorkflow<TData>(string workflowId, TData data = null, string reference=null)
50+
public Task<string> StartWorkflow<TData>(string workflowId, TData data = null, string reference = null)
5051
where TData : class, new()
5152
{
52-
return StartWorkflow<TData>(workflowId, null, data, reference);
53+
return StartWorkflow(workflowId, null, data, reference);
5354
}
5455

5556
public async Task<string> StartWorkflow<TData>(string workflowId, int? version, TData data = null, string reference=null)
@@ -203,7 +204,10 @@ public async Task<bool> TerminateWorkflow(string workflowId)
203204
try
204205
{
205206
var wf = await _persistenceStore.GetWorkflowInstance(workflowId);
207+
206208
wf.Status = WorkflowStatus.Terminated;
209+
wf.CompleteTime = _dateTimeProvider.UtcNow;
210+
207211
await _persistenceStore.PersistWorkflow(wf);
208212
await _queueProvider.QueueWork(workflowId, QueueType.Index);
209213
await _eventHub.PublishNotification(new WorkflowTerminated
@@ -225,16 +229,16 @@ await _eventHub.PublishNotification(new WorkflowTerminated
225229
public void RegisterWorkflow<TWorkflow>()
226230
where TWorkflow : IWorkflow
227231
{
228-
TWorkflow wf = ActivatorUtilities.CreateInstance<TWorkflow>(_serviceProvider);
232+
var wf = ActivatorUtilities.CreateInstance<TWorkflow>(_serviceProvider);
229233
_registry.RegisterWorkflow(wf);
230234
}
231235

232236
public void RegisterWorkflow<TWorkflow, TData>()
233237
where TWorkflow : IWorkflow<TData>
234238
where TData : new()
235239
{
236-
TWorkflow wf = ActivatorUtilities.CreateInstance<TWorkflow>(_serviceProvider);
237-
_registry.RegisterWorkflow<TData>(wf);
240+
var wf = ActivatorUtilities.CreateInstance<TWorkflow>(_serviceProvider);
241+
_registry.RegisterWorkflow(wf);
238242
}
239243
}
240244
}

src/WorkflowCore/Services/WorkflowExecutor.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
using Microsoft.Extensions.Logging;
2-
using System;
1+
using System;
32
using System.Collections.Generic;
43
using System.Linq;
54
using System.Threading;
65
using System.Threading.Tasks;
6+
7+
using Microsoft.Extensions.Logging;
78
using Microsoft.Extensions.DependencyInjection;
89
using WorkflowCore.Interface;
910
using WorkflowCore.Models;
@@ -164,7 +165,7 @@ private async Task ExecuteStep(WorkflowInstance workflow, WorkflowStep step, Exe
164165
WorkflowId = workflow.Id,
165166
ExecutionPointerId = pointer.Id,
166167
ErrorTime = _datetimeProvider.UtcNow,
167-
Message = $"Unable to construct step body {step.BodyType.ToString()}"
168+
Message = $"Unable to construct step body {step.BodyType}"
168169
});
169170
return;
170171
}

0 commit comments

Comments
 (0)