From a19abeb3741fd94653878a4779c8d9a2c52eab13 Mon Sep 17 00:00:00 2001 From: Mikhail Shilkov Date: Thu, 6 Dec 2018 17:31:02 +0100 Subject: [PATCH] An orchestrator with an input parameter --- README.md | 16 +++++++++- samples/FanOutFanIn.fs | 3 +- samples/HttpStart.fs | 6 ++-- samples/Parameters.fs | 21 +++++++++++++ samples/Typed.fs | 3 +- samples/samples.fsproj | 1 + samples/samples.sln | 31 +++++++++++++++++++ src/DurableFunctions.FSharp.sln | 25 +++++++++++++++ .../DurableFunctions.FSharp.fsproj | 1 + src/DurableFunctions.FSharp/Orchestrator.fs | 19 ++++++++++++ 10 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 samples/Parameters.fs create mode 100644 samples/samples.sln create mode 100644 src/DurableFunctions.FSharp.sln create mode 100644 src/DurableFunctions.FSharp/Orchestrator.fs diff --git a/README.md b/README.md index 4c2a621..d5d569e 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ which can be invoked from the orchestrator Azure Function: ``` fsharp [] let Run ([] context: DurableOrchestrationContext) = - workflow context + Orchestrator.run (workflow, context) ``` See [the full example](https://github.com/mikhailshilkov/DurableFunctions.FSharp/blob/master/samples/Hello.fs). @@ -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 -------------- diff --git a/samples/FanOutFanIn.fs b/samples/FanOutFanIn.fs index c2bef6d..6611e31 100644 --- a/samples/FanOutFanIn.fs +++ b/samples/FanOutFanIn.fs @@ -26,4 +26,5 @@ module FanInFanOut = let HardWork([] name) = hardWork.run name [] - let Run ([] context: DurableOrchestrationContext) = workflow context \ No newline at end of file + let Run ([] context: DurableOrchestrationContext) = + Orchestrator.run (workflow, context) \ No newline at end of file diff --git a/samples/HttpStart.fs b/samples/HttpStart.fs index eb2f951..295086b 100644 --- a/samples/HttpStart.fs +++ b/samples/HttpStart.fs @@ -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) @@ -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) diff --git a/samples/Parameters.fs b/samples/Parameters.fs new file mode 100644 index 0000000..42bd0fe --- /dev/null +++ b/samples/Parameters.fs @@ -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] + } + + [] + let Run ([] context: DurableOrchestrationContext) = + Orchestrator.run (workflow, context) \ No newline at end of file diff --git a/samples/Typed.fs b/samples/Typed.fs index c365999..54a444a 100644 --- a/samples/Typed.fs +++ b/samples/Typed.fs @@ -21,4 +21,5 @@ module TypedSequence = let SayHello([] name) = sayHello.run name [] - let Run ([] context: DurableOrchestrationContext) = workflow context \ No newline at end of file + let Run ([] context: DurableOrchestrationContext) = + Orchestrator.run (workflow, context) \ No newline at end of file diff --git a/samples/samples.fsproj b/samples/samples.fsproj index 4fcbdc5..f88acb1 100644 --- a/samples/samples.fsproj +++ b/samples/samples.fsproj @@ -8,6 +8,7 @@ + diff --git a/samples/samples.sln b/samples/samples.sln new file mode 100644 index 0000000..7a9fe75 --- /dev/null +++ b/samples/samples.sln @@ -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 diff --git a/src/DurableFunctions.FSharp.sln b/src/DurableFunctions.FSharp.sln new file mode 100644 index 0000000..b0fc2d6 --- /dev/null +++ b/src/DurableFunctions.FSharp.sln @@ -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 diff --git a/src/DurableFunctions.FSharp/DurableFunctions.FSharp.fsproj b/src/DurableFunctions.FSharp/DurableFunctions.FSharp.fsproj index 64647b2..3963239 100644 --- a/src/DurableFunctions.FSharp/DurableFunctions.FSharp.fsproj +++ b/src/DurableFunctions.FSharp/DurableFunctions.FSharp.fsproj @@ -5,6 +5,7 @@ + diff --git a/src/DurableFunctions.FSharp/Orchestrator.fs b/src/DurableFunctions.FSharp/Orchestrator.fs new file mode 100644 index 0000000..fc3dc19 --- /dev/null +++ b/src/DurableFunctions.FSharp/Orchestrator.fs @@ -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 \ No newline at end of file