Skip to content

Commit d2d3796

Browse files
committed
activity workers
1 parent a31b9e8 commit d2d3796

File tree

70 files changed

+2541
-221
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2541
-221
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ These are also available as separate Nuget packages.
166166

167167
* [Events](src/samples/WorkflowCore.Sample04)
168168

169+
* [Activity Workers](src/samples/WorkflowCore.Sample18)
170+
169171
* [Parallel Tasks](src/samples/WorkflowCore.Sample13)
170172

171173
* [Saga Transactions (with compensation)](src/samples/WorkflowCore.Sample17)

WorkflowCore.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorkflowCore.Tests.Redis",
137137
EndProject
138138
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkflowCore.DSL", "src\WorkflowCore.DSL\WorkflowCore.DSL.csproj", "{20B98905-08CB-4854-8E2C-A31A078383E9}"
139139
EndProject
140+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkflowCore.Sample18", "src\samples\WorkflowCore.Sample18\WorkflowCore.Sample18.csproj", "{5BE6D628-B9DB-4C76-AAEB-8F3800509A84}"
141+
EndProject
140142
Global
141143
GlobalSection(SolutionConfigurationPlatforms) = preSolution
142144
Debug|Any CPU = Debug|Any CPU
@@ -335,6 +337,10 @@ Global
335337
{20B98905-08CB-4854-8E2C-A31A078383E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
336338
{20B98905-08CB-4854-8E2C-A31A078383E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
337339
{20B98905-08CB-4854-8E2C-A31A078383E9}.Release|Any CPU.Build.0 = Release|Any CPU
340+
{5BE6D628-B9DB-4C76-AAEB-8F3800509A84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
341+
{5BE6D628-B9DB-4C76-AAEB-8F3800509A84}.Debug|Any CPU.Build.0 = Debug|Any CPU
342+
{5BE6D628-B9DB-4C76-AAEB-8F3800509A84}.Release|Any CPU.ActiveCfg = Release|Any CPU
343+
{5BE6D628-B9DB-4C76-AAEB-8F3800509A84}.Release|Any CPU.Build.0 = Release|Any CPU
338344
EndGlobalSection
339345
GlobalSection(SolutionProperties) = preSolution
340346
HideSolutionNode = FALSE
@@ -391,6 +397,7 @@ Global
391397
{44644716-0CE8-4837-B189-AB65AE2106AA} = {E6CEAD8D-F565-471E-A0DC-676F54EAEDEB}
392398
{78217204-B873-40B9-8875-E3925B2FBCEC} = {E6CEAD8D-F565-471E-A0DC-676F54EAEDEB}
393399
{20B98905-08CB-4854-8E2C-A31A078383E9} = {EF47161E-E399-451C-BDE8-E92AAD3BD761}
400+
{5BE6D628-B9DB-4C76-AAEB-8F3800509A84} = {5080DB09-CBE8-4C45-9957-C3BB7651755E}
394401
EndGlobalSection
395402
GlobalSection(ExtensibilityGlobals) = postSolution
396403
SolutionGuid = {DC0FA8D3-6449-4FDA-BB46-ECF58FAD23B4}

docs/activities.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Activities
2+
3+
An activity is defined as an item on an external queue of work, that a workflow can wait for.
4+
5+
In this example the workflow will wait for `activity-1`, before proceeding. It also passes the value of `data.Value1` to the activity, it then maps the result of the activity to `data.Value2`.
6+
7+
Then we create a worker to process the queue of activity items. It uses the `GetPendingActivity` method to get an activity and the data that a workflow is waiting for.
8+
9+
10+
11+
```C#
12+
public class ActivityWorkflow : IWorkflow<MyData>
13+
{
14+
public void Build(IWorkflowBuilder<MyData> builder)
15+
{
16+
builder
17+
.StartWith<HelloWorld>()
18+
.Activity("activity-1", (data) => data.Value1)
19+
.Output(data => data.Value2, step => step.Result)
20+
.Then<PrintMessage>()
21+
.Input(step => step.Message, data => data.Value2);
22+
}
23+
24+
}
25+
...
26+
27+
var activity = host.GetPendingActivity("activity-1", "worker1", TimeSpan.FromMinutes(1)).Result;
28+
29+
if (activity != null)
30+
{
31+
Console.WriteLine(activity.Parameters);
32+
host.SubmitActivitySuccess(activity.Token, "Some response data");
33+
}
34+
35+
```
36+
37+
The JSON representation of this step would look like this
38+
39+
```json
40+
{
41+
"Id": "activity-step",
42+
"StepType": "WorkflowCore.Primitives.Activity, WorkflowCore",
43+
"Inputs":
44+
{
45+
"ActivityName": "\"activity-1\"",
46+
"Parameters": "data.Value1"
47+
},
48+
"Outputs": { "Value2": "step.Result" }
49+
}
50+
```

docs/external-events.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ host.PublishEvent("MyEvent", "0", "hello");
2424
## Effective Date
2525

2626
You can also specify an effective date when waiting for events, which allows you to respond to events that may have already occurred in the past, or only ones that occur after the effective date.
27+

docs/json-yaml.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Steps:
149149

150150
### WaitFor
151151

152-
The `.WaitFor` can be implemented using 3 inputs as follows
152+
The `.WaitFor` can be implemented using inputs as follows
153153

154154
| Field | Description |
155155
| ---------------------- | --------------------------- |
@@ -184,6 +184,43 @@ Inputs:
184184
185185
```
186186

187+
### Activity
188+
189+
The `.Activity` can be implemented using inputs as follows
190+
191+
| Field | Description |
192+
| ---------------------- | --------------------------- |
193+
| CancelCondition | Optional expression to specify a cancel condition |
194+
| Inputs.ActivityName | Expression to specify the activity name |
195+
| Inputs.Parameters | Expression to specify the parameters to pass the activity worker |
196+
| Inputs.EffectiveDate | Optional expression to specify the effective date |
197+
198+
199+
```json
200+
{
201+
"Id": "MyActivityStep",
202+
"StepType": "WorkflowCore.Primitives.Activity, WorkflowCore",
203+
"NextStepId": "...",
204+
"CancelCondition": "...",
205+
"Inputs": {
206+
"ActivityName": "\"my-activity\"",
207+
"Parameters": "data.SomeValue"
208+
}
209+
}
210+
```
211+
```yaml
212+
Id: MyActivityStep
213+
StepType: WorkflowCore.Primitives.Activity, WorkflowCore
214+
NextStepId: "..."
215+
CancelCondition: "..."
216+
Inputs:
217+
ActivityName: '"my-activity"'
218+
EventKey: '"Key1"'
219+
Parameters: data.SomeValue
220+
221+
```
222+
223+
187224
### If
188225

189226
The `.If` can be implemented as follows

docs/samples.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
[Events](https://github.com/danielgerlag/workflow-core/tree/master/src/samples/WorkflowCore.Sample04)
88

9+
[Activity Workers](https://github.com/danielgerlag/workflow-core/tree/master/src/samples/WorkflowCore.Sample18)
10+
911
[Dependency Injection](https://github.com/danielgerlag/workflow-core/tree/master/src/samples/WorkflowCore.Sample15)
1012

1113
[Parallel ForEach](https://github.com/danielgerlag/workflow-core/tree/master/src/samples/WorkflowCore.Sample09)

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ nav:
33
- Home: index.md
44
- Getting started: getting-started.md
55
- External events: external-events.md
6+
- Activity workers: activities.md
67
- Error handing: error-handling.md
78
- Control structures: control-structures.md
89
- Saga transactions: sagas.md
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace WorkflowCore.Exceptions
4+
{
5+
public class ActivityFailedException : Exception
6+
{
7+
public ActivityFailedException(object data)
8+
{
9+
//
10+
}
11+
}
12+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
6+
namespace WorkflowCore.Interface
7+
{
8+
public class PendingActivity
9+
{
10+
public string Token { get; set; }
11+
public string ActivityName { get; set; }
12+
public object Parameters { get; set; }
13+
public DateTime TokenExpiry { get; set; }
14+
15+
}
16+
17+
public interface IActivityController
18+
{
19+
Task<PendingActivity> GetPendingActivity(string activityName, string workerId, TimeSpan? timeout = null);
20+
Task ReleaseActivityToken(string token);
21+
Task SubmitActivitySuccess(string token, object result);
22+
Task SubmitActivityFailure(string token, object result);
23+
24+
}
25+
}

src/WorkflowCore/Interface/IPersistenceProvider.cs

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)