-
Notifications
You must be signed in to change notification settings - Fork 54
[Durable Functions] Basic "Function Chaining" implementation #358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2079c16
Port the "Function chaining" pattern prototype from https://github.co…
AnatoliB 5f7c98b
Make the "Function Chaining" pattern work, clean the code up, add exa…
AnatoliB e82f21a
Remove the code that is not needed yet
AnatoliB cf67c93
Add line endings
AnatoliB f065205
Add line endings
AnatoliB 233df4e
Remove managed dependencies artefacts from durable samples
AnatoliB 0eeaeb8
Increase Microsoft.Azure.Functions.PowerShellWorker module version
AnatoliB dbda885
Add ValidateNotNullOrEmpty to FunctionName
AnatoliB 66c9f1c
Add a blank line
AnatoliB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .git* | ||
| .vscode | ||
| local.settings.json |
29 changes: 29 additions & 0 deletions
29
examples/durable/FunctionChainingApp/HttpTrigger/function.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "bindings": [ | ||
| { | ||
| "authLevel": "function", | ||
| "type": "httpTrigger", | ||
| "direction": "in", | ||
| "name": "Request", | ||
| "methods": [ | ||
| "get", | ||
| "post" | ||
| ] | ||
| }, | ||
| { | ||
| "type": "http", | ||
| "direction": "out", | ||
| "name": "Response" | ||
| }, | ||
| { | ||
| "name": "starter", | ||
| "type": "orchestrationClient", | ||
| "direction": "out" | ||
| }, | ||
| { | ||
| "name": "orchestrationClientIn", | ||
| "type": "orchestrationClient", | ||
| "direction": "in" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| using namespace System.Net | ||
|
|
||
| param($Request, $TriggerMetadata, $orchestrationClientIn) | ||
|
|
||
| Write-Host "HttpTrigger started" | ||
|
|
||
| $InstanceId = Start-NewOrchestration -FunctionName 'MyOrchestrator' -InputObject 'Hello' | ||
| Write-Host "Started orchestration with ID = '$InstanceId'" | ||
|
|
||
| $Response = New-OrchestrationCheckStatusResponse ` | ||
| -Request $Request ` | ||
| -OrchestrationClientData $orchestrationClientIn ` | ||
| -InstanceId $InstanceId | ||
|
|
||
| Push-OutputBinding -Name Response -Value $Response | ||
|
|
||
| Write-Host "HttpTrigger completed" |
9 changes: 9 additions & 0 deletions
9
examples/durable/FunctionChainingApp/MyOrchestrator/function.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "bindings": [ | ||
| { | ||
| "name": "Context", | ||
| "type": "orchestrationTrigger", | ||
| "direction": "in" | ||
| } | ||
| ] | ||
| } |
15 changes: 15 additions & 0 deletions
15
examples/durable/FunctionChainingApp/MyOrchestrator/run.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| using namespace System.Net | ||
|
|
||
| param($Context) | ||
|
|
||
| Write-Host "MyOrchestrator: started. Input: $($Context.Input)" | ||
|
|
||
| $output = @() | ||
|
|
||
| $output += Invoke-ActivityFunctionAsync -FunctionName "SayHello" -Input "Tokyo" | ||
| $output += Invoke-ActivityFunctionAsync -FunctionName "SayHello" -Input "Seattle" -Verbose | ||
| $output += Invoke-ActivityFunctionAsync -FunctionName "SayHello" -Input "London" -Verbose | ||
|
|
||
| Write-Host "MyOrchestrator: finished." | ||
|
|
||
| return $output | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "bindings": [ | ||
| { | ||
| "name": "name", | ||
| "type": "activityTrigger", | ||
| "direction": "in" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| param($name) | ||
|
|
||
| Write-Host "SayHello($name) started" | ||
| Start-Sleep -Seconds 5 | ||
| Write-Host "SayHello($name) finished" | ||
| return "Hello $name" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>netstandard2.0</TargetFramework> | ||
| <WarningsAsErrors></WarningsAsErrors> | ||
| <DefaultItemExcludes>**</DefaultItemExcludes> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="1.8.3" /> | ||
| <PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.1.0" /> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "version": "2.0" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Azure Functions profile.ps1 | ||
| # | ||
| # This profile.ps1 will get executed every "cold start" of your Function App. | ||
| # "cold start" occurs when: | ||
| # | ||
| # * A Function App starts up for the very first time | ||
| # * A Function App starts up after being de-allocated due to inactivity | ||
| # | ||
| # You can define helper functions, run commands, or specify environment variables | ||
| # NOTE: any variables defined that are not environment variables will get reset after the first execution | ||
|
|
||
| # Authenticate with Azure PowerShell using MSI. | ||
| # Remove this if you are not planning on using MSI or Azure PowerShell. | ||
| if ($env:MSI_SECRET -and (Get-Module -ListAvailable Az.Accounts)) { | ||
| Connect-AzAccount -Identity | ||
| } | ||
|
|
||
| # Uncomment the next line to enable legacy AzureRm alias in Azure PowerShell. | ||
| # Enable-AzureRmAlias | ||
|
|
||
| # You can also define functions or aliases that can be referenced in any of your PowerShell functions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "$schema": "http://json.schemastore.org/proxies", | ||
| "proxies": {} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .git* | ||
| .vscode | ||
| local.settings.json |
29 changes: 29 additions & 0 deletions
29
examples/durable/LongRunningHttpApp/HttpTrigger/function.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "bindings": [ | ||
| { | ||
| "authLevel": "function", | ||
| "type": "httpTrigger", | ||
| "direction": "in", | ||
| "name": "Request", | ||
| "methods": [ | ||
| "get", | ||
| "post" | ||
| ] | ||
| }, | ||
| { | ||
| "type": "http", | ||
| "direction": "out", | ||
| "name": "Response" | ||
| }, | ||
| { | ||
| "name": "starter", | ||
| "type": "orchestrationClient", | ||
| "direction": "out" | ||
| }, | ||
| { | ||
| "name": "orchestrationClientIn", | ||
| "type": "orchestrationClient", | ||
| "direction": "in" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| using namespace System.Net | ||
|
|
||
| param($Request, $TriggerMetadata, $orchestrationClientIn) | ||
|
|
||
| Write-Host "HttpTrigger started" | ||
|
|
||
| $InstanceId = Start-NewOrchestration -FunctionName 'MyOrchestrator' -InputObject $Request.Query | ||
|
|
||
| Write-Host "Started orchestration with ID = '$InstanceId'" | ||
|
|
||
| $Response = New-OrchestrationCheckStatusResponse ` | ||
| -Request $Request ` | ||
| -OrchestrationClientData $orchestrationClientIn ` | ||
| -InstanceId $InstanceId | ||
|
|
||
| Push-OutputBinding -Name Response -Value $Response | ||
|
|
||
| Write-Host "HttpTrigger completed" |
9 changes: 9 additions & 0 deletions
9
examples/durable/LongRunningHttpApp/LongRunningActivity/function.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "bindings": [ | ||
| { | ||
| "name": "inputData", | ||
| "type": "activityTrigger", | ||
| "direction": "in" | ||
| } | ||
| ] | ||
| } |
19 changes: 19 additions & 0 deletions
19
examples/durable/LongRunningHttpApp/LongRunningActivity/run.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| param($InputData) | ||
|
|
||
| $name = $InputData.Name | ||
| $durationSeconds = $InputData.DurationSeconds | ||
|
|
||
| $activityTraceHeader = "LongRunningActivity($name, $durationSeconds)" | ||
| Write-Host "$activityTraceHeader started" | ||
|
|
||
| $startedAt = Get-Date | ||
| $runUntil = (Get-Date) + (New-TimeSpan -Seconds $durationSeconds) | ||
| Write-Host "$activityTraceHeader will run until $($runUntil.ToUniversalTime())" | ||
| while ((Get-Date) -lt $runUntil) { | ||
| Start-Sleep -Seconds ([Math]::Min($durationSeconds, 10)) | ||
| Write-Host "$activityTraceHeader is still running: $([Math]::Truncate(((Get-Date) - $startedAt).TotalMinutes)) minute(s)" | ||
| } | ||
|
|
||
| Write-Host "$activityTraceHeader finished" | ||
|
|
||
| return "Hello $name" |
9 changes: 9 additions & 0 deletions
9
examples/durable/LongRunningHttpApp/MyOrchestrator/function.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "bindings": [ | ||
| { | ||
| "name": "Context", | ||
| "type": "orchestrationTrigger", | ||
| "direction": "in" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| param($Context) | ||
|
|
||
| Write-Host "MyOrchestrator: started. Input: $($Context.Input)" | ||
|
|
||
| $activityResult = Invoke-ActivityFunctionAsync -FunctionName "LongRunningActivity" -Input $Context.Input | ||
| Write-Host "MyOrchestrator: Returned from LongRunningActivity: '$activityResult'" | ||
|
|
||
| Write-Host "MyOrchestrator: finished." | ||
| return $activityResult |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>netstandard2.0</TargetFramework> | ||
| <WarningsAsErrors></WarningsAsErrors> | ||
| <DefaultItemExcludes>**</DefaultItemExcludes> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="1.8.3" /> | ||
| <PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.1.0" /> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "version": "2.0", | ||
| "functionTimeout": "02:00:00" | ||
Francisco-Gamino marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Azure Functions profile.ps1 | ||
| # | ||
| # This profile.ps1 will get executed every "cold start" of your Function App. | ||
| # "cold start" occurs when: | ||
| # | ||
| # * A Function App starts up for the very first time | ||
| # * A Function App starts up after being de-allocated due to inactivity | ||
| # | ||
| # You can define helper functions, run commands, or specify environment variables | ||
| # NOTE: any variables defined that are not environment variables will get reset after the first execution | ||
|
|
||
| # Authenticate with Azure PowerShell using MSI. | ||
| # Remove this if you are not planning on using MSI or Azure PowerShell. | ||
| if ($env:MSI_SECRET -and (Get-Module -ListAvailable Az.Accounts)) { | ||
| Connect-AzAccount -Identity | ||
| } | ||
|
|
||
| # Uncomment the next line to enable legacy AzureRm alias in Azure PowerShell. | ||
| # Enable-AzureRmAlias | ||
|
|
||
| # You can also define functions or aliases that can be referenced in any of your PowerShell functions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "$schema": "http://json.schemastore.org/proxies", | ||
| "proxies": {} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
| // | ||
|
|
||
| namespace Microsoft.Azure.Functions.PowerShellWorker.Durable | ||
| { | ||
| /// <summary> | ||
| /// Action types | ||
| /// </summary> | ||
| internal enum ActionType | ||
| { | ||
| /// <summary> | ||
| /// Call an activity function. | ||
| /// </summary> | ||
| CallActivity = 0, | ||
|
|
||
| /// <summary> | ||
| /// Call an activity function with retry. | ||
| /// </summary> | ||
| CallActivityWithRetry = 1, | ||
|
|
||
| /// <summary> | ||
| /// Call a sub-orchestration function. | ||
| /// </summary> | ||
| CallSubOrchestrator = 2, | ||
|
|
||
| /// <summary> | ||
| /// Call a sub-orchestration function with retry. | ||
| /// </summary> | ||
| CallSubOrchestratorWithRetry = 3, | ||
|
|
||
| /// <summary> | ||
| /// Run the orchestration function as a loop. | ||
| /// </summary> | ||
| ContinueAsNew = 4, | ||
|
|
||
| /// <summary> | ||
| /// Create a timer. | ||
| /// </summary> | ||
| CreateTimer = 5, | ||
|
|
||
| /// <summary> | ||
| /// Wait for an external event. | ||
| /// </summary> | ||
| WaitForExternalEvent = 6, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
| // | ||
|
|
||
| namespace Microsoft.Azure.Functions.PowerShellWorker.Durable | ||
| { | ||
| /// <summary> | ||
| /// An orchestration action that represents calling an activity function. | ||
| /// </summary> | ||
| internal class CallActivityAction : OrchestrationAction | ||
| { | ||
| /// <summary> | ||
| /// The activity function name. | ||
| /// </summary> | ||
| public readonly string FunctionName; | ||
|
|
||
| /// <summary> | ||
| /// The input to the activity function. | ||
| /// </summary> | ||
| public readonly object Input; | ||
|
|
||
| public CallActivityAction(string functionName, object input) | ||
| : base(ActionType.CallActivity) | ||
| { | ||
| FunctionName = functionName; | ||
| Input = input; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.