Skip to content

Commit 687bf23

Browse files
committed
ability to schedule execution pointers dependent another pointer completing first
1 parent 2858f66 commit 687bf23

File tree

7 files changed

+40
-12
lines changed

7 files changed

+40
-12
lines changed

WorkflowCore.sln

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ReleaseNotes", "ReleaseNote
103103
ReleaseNotes\2.1.2.md = ReleaseNotes\2.1.2.md
104104
ReleaseNotes\3.0.0.md = ReleaseNotes\3.0.0.md
105105
ReleaseNotes\3.1.0.md = ReleaseNotes\3.1.0.md
106+
ReleaseNotes\3.3.0.md = ReleaseNotes\3.3.0.md
106107
EndProjectSection
107108
EndProject
108109
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorkflowCore.Sample14", "src\samples\WorkflowCore.Sample14\WorkflowCore.Sample14.csproj", "{6BC66637-B42A-4334-ADFB-DBEC9F29D293}"
@@ -145,9 +146,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorkflowCore.Sample09s", "s
145146
EndProject
146147
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScratchPad", "test\ScratchPad\ScratchPad.csproj", "{51BB7DCD-01DD-453D-A1E7-17E5E3DBB14C}"
147148
EndProject
148-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkflowCore.Tests.QueueProviders.RabbitMQ", "test\WorkflowCore.Tests.QueueProviders.RabbitMQ\WorkflowCore.Tests.QueueProviders.RabbitMQ.csproj", "{54DE20BA-EBA7-4BF0-9BD9-F03766849716}"
149+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorkflowCore.Tests.QueueProviders.RabbitMQ", "test\WorkflowCore.Tests.QueueProviders.RabbitMQ\WorkflowCore.Tests.QueueProviders.RabbitMQ.csproj", "{54DE20BA-EBA7-4BF0-9BD9-F03766849716}"
149150
EndProject
150-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkflowCore.Sample19", "src\samples\WorkflowCore.Sample19\WorkflowCore.Sample19.csproj", "{1223ED47-3E5E-4960-B70D-DFAF550F6666}"
151+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorkflowCore.Sample19", "src\samples\WorkflowCore.Sample19\WorkflowCore.Sample19.csproj", "{1223ED47-3E5E-4960-B70D-DFAF550F6666}"
151152
EndProject
152153
Global
153154
GlobalSection(SolutionConfigurationPlatforms) = preSolution

src/WorkflowCore/Models/ExecutionPointer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public enum PointerStatus
6363
WaitingForEvent = 5,
6464
Failed = 6,
6565
Compensated = 7,
66-
Cancelled = 8
66+
Cancelled = 8,
67+
PendingPredecessor = 9
6768
}
6869
}

src/WorkflowCore/Models/ExecutionPointerCollection.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ public ExecutionPointer Find(Predicate<ExecutionPointer> match)
9797
return _dictionary.Values.FirstOrDefault(x => match(x));
9898
}
9999

100+
public ICollection<ExecutionPointer> FindByStatus(PointerStatus status)
101+
{
102+
//TODO: track states in hash table
103+
return _dictionary.Values.Where(x => x.Status == status).ToList();
104+
}
105+
100106
public int Count => _dictionary.Count;
101107
public bool IsReadOnly => false;
102108
}

src/WorkflowCore/Services/ErrorHandlers/CompensateHandler.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@ public void Handle(WorkflowInstance workflow, WorkflowDefinition def, ExecutionP
6363
scopePointer.EndTime = _datetimeProvider.UtcNow;
6464
scopePointer.Status = PointerStatus.Failed;
6565

66+
ExecutionPointer compensationPointer = null;
67+
6668
if (scopeStep.CompensationStepId.HasValue)
6769
{
6870
scopePointer.Status = PointerStatus.Compensated;
6971

70-
var compensationPointer = _pointerFactory.BuildCompensationPointer(def, scopePointer, exceptionPointer, scopeStep.CompensationStepId.Value);
72+
compensationPointer = _pointerFactory.BuildCompensationPointer(def, scopePointer, exceptionPointer, scopeStep.CompensationStepId.Value);
7173
workflow.ExecutionPointers.Add(compensationPointer);
7274

7375
if (resume)
@@ -89,8 +91,16 @@ public void Handle(WorkflowInstance workflow, WorkflowDefinition def, ExecutionP
8991
var siblingStep = def.Steps.FindById(siblingPointer.StepId);
9092
if (siblingStep.CompensationStepId.HasValue)
9193
{
92-
var compensationPointer = _pointerFactory.BuildCompensationPointer(def, siblingPointer, exceptionPointer, siblingStep.CompensationStepId.Value);
93-
workflow.ExecutionPointers.Add(compensationPointer);
94+
var nextCompensationPointer = _pointerFactory.BuildCompensationPointer(def, siblingPointer, exceptionPointer, siblingStep.CompensationStepId.Value);
95+
if (compensationPointer != null)
96+
{
97+
nextCompensationPointer.Active = false;
98+
nextCompensationPointer.Status = PointerStatus.PendingPredecessor;
99+
nextCompensationPointer.PredecessorId = compensationPointer.Id;
100+
compensationPointer = nextCompensationPointer;
101+
}
102+
workflow.ExecutionPointers.Add(nextCompensationPointer);
103+
94104
siblingPointer.Status = PointerStatus.Compensated;
95105
}
96106
}

src/WorkflowCore/Services/ExecutionResultProcessor.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ public void ProcessExecutionResult(WorkflowInstance workflow, WorkflowDefinition
6767
workflow.ExecutionPointers.Add(_pointerFactory.BuildNextPointer(def, pointer, outcomeTarget));
6868
}
6969

70+
var pendingSubsequents = workflow.ExecutionPointers
71+
.FindByStatus(PointerStatus.PendingPredecessor)
72+
.Where(x => x.PredecessorId == pointer.Id);
73+
74+
foreach (var subsequent in pendingSubsequents)
75+
{
76+
subsequent.Status = PointerStatus.Pending;
77+
subsequent.Active = true;
78+
}
79+
7080
_eventPublisher.PublishNotification(new StepCompleted()
7181
{
7282
EventTimeUtc = _datetimeProvider.UtcNow,

src/WorkflowCore/WorkflowCore.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
1616
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
1717
<Description>Workflow Core is a light weight workflow engine targeting .NET Standard.</Description>
18-
<Version>3.3.1</Version>
19-
<AssemblyVersion>3.3.1.0</AssemblyVersion>
20-
<FileVersion>3.3.1.0</FileVersion>
18+
<Version>3.3.2</Version>
19+
<AssemblyVersion>3.3.2.0</AssemblyVersion>
20+
<FileVersion>3.3.2.0</FileVersion>
2121
<PackageReleaseNotes></PackageReleaseNotes>
2222
<PackageIconUrl>https://github.com/danielgerlag/workflow-core/raw/master/src/logo.png</PackageIconUrl>
23-
<PackageVersion>3.3.1</PackageVersion>
23+
<PackageVersion>3.3.2</PackageVersion>
2424
</PropertyGroup>
2525

2626
<ItemGroup>

test/WorkflowCore.IntegrationTests/Scenarios/MultistepCompensationScenario.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public void Build(IWorkflowBuilder<object> builder)
3434
Compensation1Fired = CompensationCounter;
3535
})
3636
.Then(context => ExecutionResult.Next())
37-
.CompensateWith(context =>
37+
.CompensateWithSequence(context => context.StartWith(c =>
3838
{
3939
CompensationCounter++;
4040
Compensation2Fired = CompensationCounter;
41-
})
41+
}))
4242
.Then(context => ExecutionResult.Next())
4343
.CompensateWith(context =>
4444
{

0 commit comments

Comments
 (0)