Skip to content

Commit 58adab7

Browse files
authored
Add starter function-chaining sample (#57)
1 parent dd955db commit 58adab7

File tree

11 files changed

+170
-0
lines changed

11 files changed

+170
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.git*
2+
.vscode
3+
__azurite_db*__.json
4+
__blobstorage__
5+
__queuestorage__
6+
local.settings.json
7+
test
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"bindings": [
3+
{
4+
"authLevel": "anonymous",
5+
"name": "Request",
6+
"type": "httpTrigger",
7+
"direction": "in",
8+
"route": "orchestrators/{FunctionName}",
9+
"methods": [
10+
"post",
11+
"get"
12+
]
13+
},
14+
{
15+
"type": "http",
16+
"direction": "out",
17+
"name": "Response"
18+
},
19+
{
20+
"name": "starter",
21+
"type": "durableClient",
22+
"direction": "in"
23+
}
24+
]
25+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using namespace System.Net
2+
3+
param($Request, $TriggerMetadata)
4+
5+
$FunctionName = $Request.Params.FunctionName
6+
$InstanceId = Start-DurableOrchestration -FunctionName $FunctionName -Input "I wrote this in DurableFunctionsHttpStart"
7+
Write-Host "Started orchestration with ID = '$InstanceId'"
8+
9+
$Response = New-DurableOrchestrationCheckStatusResponse -Request $Request -InstanceId $InstanceId
10+
Push-OutputBinding -Name Response -Value $Response
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"bindings": [
3+
{
4+
"name": "Context",
5+
"type": "orchestrationTrigger",
6+
"direction": "in"
7+
}
8+
]
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
param($Context)
2+
3+
$output = @()
4+
5+
# Function chaining
6+
$output += Invoke-DurableActivity -FunctionName 'Hello' -Input 'Tokyo'
7+
$output += Invoke-DurableActivity -FunctionName 'Hello' -Input 'Seattle'
8+
$output += Invoke-DurableActivity -FunctionName 'Hello' -Input 'London'
9+
10+
# final expression is the return statement
11+
$output
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"bindings": [
3+
{
4+
"name": "name",
5+
"type": "activityTrigger",
6+
"direction": "in"
7+
}
8+
]
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
param($name)
2+
3+
"Hello $name!"

samples/functionChaining/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Function Chaining sample
2+
3+
## Pre-requisites
4+
5+
You'll need core tools version v4.0.5095+. Please run `func --version` to ensure your core tools version is compatible.
6+
7+
## How to try it out
8+
9+
This repo already contains the basic project structure for a function-chaining Durable Functions PowerShell app.
10+
You may use this as the starting point for experimentation.
11+
12+
### 1. Install the SDK from the PowerShell Gallery
13+
14+
This has been done for you in `requirements.psd1`, by including the following line:
15+
16+
```json
17+
'AzureFunctions.PowerShell.Durable.SDK' = '1.0.0-alpha'
18+
```
19+
20+
### 2. Import the SDK in your `profile.ps1`.
21+
22+
This has been done for you in this starter project.
23+
Please verify that the `profile.ps1` file contains the following line:
24+
25+
```powershell
26+
Import-Module AzureFunctions.PowerShell.Durable.SDK -ErrorAction Stop
27+
```
28+
29+
### 3. Set the env variable `ExternalDurablePowerShellSDK` to `"true"`.
30+
31+
This has been done for you in this repo's starter project.
32+
Please verify that this setting is set in your `local.settings.json`.
33+
34+
### 4. Try it!
35+
36+
Run `func host start` and run the orchestrator with a GET request to `http://localhost:7071/api/orchestrators/DurableFunctionsOrchestrator`.
37+
38+
### 6. Confirm you're using the new SDK
39+
40+
Since the new SDK is backwards compatible with the old one, it's worth doing a sanity check that you are actually using the new experience.
41+
42+
To do this, run `func host start --verbose`, start the orchestrator by performing a GET request to `http://localhost:7071/api/orchestrators/DurableFunctionsOrchestrator`, and finally CTRL+F for the following log: `Utilizing external Durable Functions SDK: 'True'`. If you can find it, you're using the new experience.
43+
44+
## If you deploy to Azure
45+
46+
You will need to set the `ExternalDurablePowerShellSDK` application setting to `"true"`.

samples/functionChaining/host.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"version": "2.0",
3+
"logging": {
4+
"applicationInsights": {
5+
"samplingSettings": {
6+
"isEnabled": true,
7+
"excludedTypes": "Request"
8+
}
9+
}
10+
},
11+
"managedDependency": {
12+
"enabled": true
13+
},
14+
"extensionBundle": {
15+
"id": "Microsoft.Azure.Functions.ExtensionBundle",
16+
"version": "[3.*, 4.0.0)"
17+
},
18+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Azure Functions profile.ps1
2+
#
3+
# This profile.ps1 will get executed every "cold start" of your Function App.
4+
# "cold start" occurs when:
5+
#
6+
# * A Function App starts up for the very first time
7+
# * A Function App starts up after being de-allocated due to inactivity
8+
#
9+
# You can define helper functions, run commands, or specify environment variables
10+
# NOTE: any variables defined that are not environment variables will get reset after the first execution
11+
12+
# Authenticate with Azure PowerShell using MSI.
13+
# Remove this if you are not planning on using MSI or Azure PowerShell.
14+
if ($env:MSI_SECRET) {
15+
Disable-AzContextAutosave -Scope Process | Out-Null
16+
Connect-AzAccount -Identity
17+
}
18+
19+
# Uncomment the next line to enable legacy AzureRm alias in Azure PowerShell.
20+
# Enable-AzureRmAlias
21+
22+
# You can also define functions or aliases that can be referenced in any of your PowerShell functions.
23+
Import-Module AzureFunctions.PowerShell.Durable.SDK -ErrorAction Stop

0 commit comments

Comments
 (0)