Skip to content

Commit

Permalink
An orchestrator with an input parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Shilkov committed Dec 6, 2018
1 parent 9f3f7f5 commit a19abeb
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 5 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ which can be invoked from the orchestrator Azure Function:
``` fsharp
[<FunctionName("HelloSequence")>]
let Run ([<OrchestrationTrigger>] context: DurableOrchestrationContext) =
workflow context
Orchestrator.run (workflow, context)
```

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

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

Orchestrator with an input parameter
------------------------------------

Orchestrators can accept an input parameter (1 at most). This can be defined as an argument of the workflow
definition function:

``` fsharp
let workflow input = orchestrator {
// ...
}
```

An overload of `Orchestrator.run` will get the input from the context and pass it to the workflow.

Fan-out/fan-in
--------------

Expand Down
3 changes: 2 additions & 1 deletion samples/FanOutFanIn.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ module FanInFanOut =
let HardWork([<ActivityTrigger>] name) = hardWork.run name

[<FunctionName("FanInFanOut")>]
let Run ([<OrchestrationTrigger>] context: DurableOrchestrationContext) = workflow context
let Run ([<OrchestrationTrigger>] context: DurableOrchestrationContext) =
Orchestrator.run (workflow, context)
6 changes: 4 additions & 2 deletions samples/HttpStart.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module HttpStart =
functionName: string,
log: ILogger) =
task {
let! instanceId = starter.StartNewAsync (functionName, "")
let param = req.RequestUri.ParseQueryString().["input"]
let! instanceId = starter.StartNewAsync (functionName, param)

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

Expand All @@ -30,7 +31,8 @@ module HttpStart =
functionName: string,
log: ILogger) =
task {
let! instanceId = starter.StartNewAsync (functionName, "")
let param = req.RequestUri.ParseQueryString().["input"]
let! instanceId = starter.StartNewAsync (functionName, param)

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

Expand Down
21 changes: 21 additions & 0 deletions samples/Parameters.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace samples

open Microsoft.Azure.WebJobs
open DurableFunctions.FSharp

open TypedSequence

module InputParameter =

let workflow input = orchestrator {
let! hello1 = Activity.call sayHello (input + " Tokyo")
let! hello2 = Activity.call sayHello (input + " Seattle")
let! hello3 = Activity.call sayHello (input + " London")

// given "Bla" returns ["Hello Bla Tokyo!", "Hello Bla Seattle!", "Hello Bla London!"]
return [hello1; hello2; hello3]
}

[<FunctionName("WorkflowWithInputParameter")>]
let Run ([<OrchestrationTrigger>] context: DurableOrchestrationContext) =
Orchestrator.run (workflow, context)
3 changes: 2 additions & 1 deletion samples/Typed.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ module TypedSequence =
let SayHello([<ActivityTrigger>] name) = sayHello.run name

[<FunctionName("TypedSequence")>]
let Run ([<OrchestrationTrigger>] context: DurableOrchestrationContext) = workflow context
let Run ([<OrchestrationTrigger>] context: DurableOrchestrationContext) =
Orchestrator.run (workflow, context)
1 change: 1 addition & 0 deletions samples/samples.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<ItemGroup>
<Compile Include="Hello.fs" />
<Compile Include="Typed.fs" />
<Compile Include="Parameters.fs" />
<Compile Include="FanOutFanIn.fs" />
<Compile Include="HttpStart.fs" />
</ItemGroup>
Expand Down
31 changes: 31 additions & 0 deletions samples/samples.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.106
MinimumVisualStudioVersion = 10.0.40219.1
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "samples", "samples.fsproj", "{4F0C07E8-110A-401C-9AA6-F5D93366110B}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "DurableFunctions.FSharp", "..\src\DurableFunctions.FSharp\DurableFunctions.FSharp.fsproj", "{B6FE2E57-18D5-4C14-8B17-2074E39428CA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4F0C07E8-110A-401C-9AA6-F5D93366110B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F0C07E8-110A-401C-9AA6-F5D93366110B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F0C07E8-110A-401C-9AA6-F5D93366110B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F0C07E8-110A-401C-9AA6-F5D93366110B}.Release|Any CPU.Build.0 = Release|Any CPU
{B6FE2E57-18D5-4C14-8B17-2074E39428CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6FE2E57-18D5-4C14-8B17-2074E39428CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6FE2E57-18D5-4C14-8B17-2074E39428CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6FE2E57-18D5-4C14-8B17-2074E39428CA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C0A21BDC-E18B-479C-AAFF-C305569CCF13}
EndGlobalSection
EndGlobal
25 changes: 25 additions & 0 deletions src/DurableFunctions.FSharp.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.106
MinimumVisualStudioVersion = 10.0.40219.1
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "DurableFunctions.FSharp", "DurableFunctions.FSharp\DurableFunctions.FSharp.fsproj", "{23142B6C-108F-4C1C-8A40-9BCE38D01890}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{23142B6C-108F-4C1C-8A40-9BCE38D01890}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{23142B6C-108F-4C1C-8A40-9BCE38D01890}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23142B6C-108F-4C1C-8A40-9BCE38D01890}.Release|Any CPU.ActiveCfg = Release|Any CPU
{23142B6C-108F-4C1C-8A40-9BCE38D01890}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {08BC5382-2949-432C-8F9C-C2BE31BA58AC}
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions src/DurableFunctions.FSharp/DurableFunctions.FSharp.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<ItemGroup>
<Compile Include="OrchestratorCE.fs" />
<Compile Include="Activity.fs" />
<Compile Include="Orchestrator.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="1.7.0" />
Expand Down
19 changes: 19 additions & 0 deletions src/DurableFunctions.FSharp/Orchestrator.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace DurableFunctions.FSharp

open System.Threading.Tasks
open Microsoft.Azure.WebJobs
open OrchestratorBuilder

type Orchestrator = class

/// Runs a workflow which expects an input parameter by reading this parameter from
/// the orchestration context.
static member run (workflow : ContextTask<'b>, context : DurableOrchestrationContext) : Task<'b> =
workflow context

/// Runs a workflow which expects an input parameter by reading this parameter from
/// the orchestration context.
static member run (workflow : 'a -> ContextTask<'b>, context : DurableOrchestrationContext) : Task<'b> =
let input = context.GetInput<'a> ()
workflow input context
end

0 comments on commit a19abeb

Please sign in to comment.