Skip to content

Commit a19abeb

Browse files
author
Mikhail Shilkov
committed
An orchestrator with an input parameter
1 parent 9f3f7f5 commit a19abeb

10 files changed

Lines changed: 121 additions & 5 deletions

File tree

‎README.md‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ which can be invoked from the orchestrator Azure Function:
5353
``` fsharp
5454
[<FunctionName("HelloSequence")>]
5555
let Run ([<OrchestrationTrigger>] context: DurableOrchestrationContext) =
56-
workflow context
56+
Orchestrator.run (workflow, context)
5757
```
5858

5959
See [the full example](https://github.com/mikhailshilkov/DurableFunctions.FSharp/blob/master/samples/Hello.fs).
@@ -111,6 +111,20 @@ let hardWork =
111111

112112
See [the full example](https://github.com/mikhailshilkov/DurableFunctions.FSharp/blob/master/samples/FanOutFanIn.fs).
113113

114+
Orchestrator with an input parameter
115+
------------------------------------
116+
117+
Orchestrators can accept an input parameter (1 at most). This can be defined as an argument of the workflow
118+
definition function:
119+
120+
``` fsharp
121+
let workflow input = orchestrator {
122+
// ...
123+
}
124+
```
125+
126+
An overload of `Orchestrator.run` will get the input from the context and pass it to the workflow.
127+
114128
Fan-out/fan-in
115129
--------------
116130

‎samples/FanOutFanIn.fs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ module FanInFanOut =
2626
let HardWork([<ActivityTrigger>] name) = hardWork.run name
2727

2828
[<FunctionName("FanInFanOut")>]
29-
let Run ([<OrchestrationTrigger>] context: DurableOrchestrationContext) = workflow context
29+
let Run ([<OrchestrationTrigger>] context: DurableOrchestrationContext) =
30+
Orchestrator.run (workflow, context)

‎samples/HttpStart.fs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ module HttpStart =
1616
functionName: string,
1717
log: ILogger) =
1818
task {
19-
let! instanceId = starter.StartNewAsync (functionName, "")
19+
let param = req.RequestUri.ParseQueryString().["input"]
20+
let! instanceId = starter.StartNewAsync (functionName, param)
2021

2122
log.LogInformation(sprintf "Started orchestration with ID = '{%s}'." instanceId)
2223

@@ -30,7 +31,8 @@ module HttpStart =
3031
functionName: string,
3132
log: ILogger) =
3233
task {
33-
let! instanceId = starter.StartNewAsync (functionName, "")
34+
let param = req.RequestUri.ParseQueryString().["input"]
35+
let! instanceId = starter.StartNewAsync (functionName, param)
3436

3537
log.LogInformation(sprintf "Started orchestration with ID = '{%s}'." instanceId)
3638

‎samples/Parameters.fs‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace samples
2+
3+
open Microsoft.Azure.WebJobs
4+
open DurableFunctions.FSharp
5+
6+
open TypedSequence
7+
8+
module InputParameter =
9+
10+
let workflow input = orchestrator {
11+
let! hello1 = Activity.call sayHello (input + " Tokyo")
12+
let! hello2 = Activity.call sayHello (input + " Seattle")
13+
let! hello3 = Activity.call sayHello (input + " London")
14+
15+
// given "Bla" returns ["Hello Bla Tokyo!", "Hello Bla Seattle!", "Hello Bla London!"]
16+
return [hello1; hello2; hello3]
17+
}
18+
19+
[<FunctionName("WorkflowWithInputParameter")>]
20+
let Run ([<OrchestrationTrigger>] context: DurableOrchestrationContext) =
21+
Orchestrator.run (workflow, context)

‎samples/Typed.fs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ module TypedSequence =
2121
let SayHello([<ActivityTrigger>] name) = sayHello.run name
2222

2323
[<FunctionName("TypedSequence")>]
24-
let Run ([<OrchestrationTrigger>] context: DurableOrchestrationContext) = workflow context
24+
let Run ([<OrchestrationTrigger>] context: DurableOrchestrationContext) =
25+
Orchestrator.run (workflow, context)

‎samples/samples.fsproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<ItemGroup>
99
<Compile Include="Hello.fs" />
1010
<Compile Include="Typed.fs" />
11+
<Compile Include="Parameters.fs" />
1112
<Compile Include="FanOutFanIn.fs" />
1213
<Compile Include="HttpStart.fs" />
1314
</ItemGroup>

‎samples/samples.sln‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28307.106
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "samples", "samples.fsproj", "{4F0C07E8-110A-401C-9AA6-F5D93366110B}"
7+
EndProject
8+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "DurableFunctions.FSharp", "..\src\DurableFunctions.FSharp\DurableFunctions.FSharp.fsproj", "{B6FE2E57-18D5-4C14-8B17-2074E39428CA}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{4F0C07E8-110A-401C-9AA6-F5D93366110B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{4F0C07E8-110A-401C-9AA6-F5D93366110B}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{4F0C07E8-110A-401C-9AA6-F5D93366110B}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{4F0C07E8-110A-401C-9AA6-F5D93366110B}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{B6FE2E57-18D5-4C14-8B17-2074E39428CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{B6FE2E57-18D5-4C14-8B17-2074E39428CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{B6FE2E57-18D5-4C14-8B17-2074E39428CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{B6FE2E57-18D5-4C14-8B17-2074E39428CA}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {C0A21BDC-E18B-479C-AAFF-C305569CCF13}
30+
EndGlobalSection
31+
EndGlobal

‎src/DurableFunctions.FSharp.sln‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28307.106
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "DurableFunctions.FSharp", "DurableFunctions.FSharp\DurableFunctions.FSharp.fsproj", "{23142B6C-108F-4C1C-8A40-9BCE38D01890}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{23142B6C-108F-4C1C-8A40-9BCE38D01890}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{23142B6C-108F-4C1C-8A40-9BCE38D01890}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{23142B6C-108F-4C1C-8A40-9BCE38D01890}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{23142B6C-108F-4C1C-8A40-9BCE38D01890}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {08BC5382-2949-432C-8F9C-C2BE31BA58AC}
24+
EndGlobalSection
25+
EndGlobal

‎src/DurableFunctions.FSharp/DurableFunctions.FSharp.fsproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<ItemGroup>
66
<Compile Include="OrchestratorCE.fs" />
77
<Compile Include="Activity.fs" />
8+
<Compile Include="Orchestrator.fs" />
89
</ItemGroup>
910
<ItemGroup>
1011
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="1.7.0" />
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace DurableFunctions.FSharp
2+
3+
open System.Threading.Tasks
4+
open Microsoft.Azure.WebJobs
5+
open OrchestratorBuilder
6+
7+
type Orchestrator = class
8+
9+
/// Runs a workflow which expects an input parameter by reading this parameter from
10+
/// the orchestration context.
11+
static member run (workflow : ContextTask<'b>, context : DurableOrchestrationContext) : Task<'b> =
12+
workflow context
13+
14+
/// Runs a workflow which expects an input parameter by reading this parameter from
15+
/// the orchestration context.
16+
static member run (workflow : 'a -> ContextTask<'b>, context : DurableOrchestrationContext) : Task<'b> =
17+
let input = context.GetInput<'a> ()
18+
workflow input context
19+
end

0 commit comments

Comments
 (0)