diff --git a/samples/functionChaining/.funcignore b/samples/functionChaining/.funcignore new file mode 100644 index 0000000..dc267b1 --- /dev/null +++ b/samples/functionChaining/.funcignore @@ -0,0 +1,7 @@ +.git* +.vscode +__azurite_db*__.json +__blobstorage__ +__queuestorage__ +local.settings.json +test \ No newline at end of file diff --git a/samples/functionChaining/DurableFunctionsHttpStart/function.json b/samples/functionChaining/DurableFunctionsHttpStart/function.json new file mode 100644 index 0000000..2ed82d2 --- /dev/null +++ b/samples/functionChaining/DurableFunctionsHttpStart/function.json @@ -0,0 +1,25 @@ +{ + "bindings": [ + { + "authLevel": "anonymous", + "name": "Request", + "type": "httpTrigger", + "direction": "in", + "route": "orchestrators/{FunctionName}", + "methods": [ + "post", + "get" + ] + }, + { + "type": "http", + "direction": "out", + "name": "Response" + }, + { + "name": "starter", + "type": "durableClient", + "direction": "in" + } + ] +} \ No newline at end of file diff --git a/samples/functionChaining/DurableFunctionsHttpStart/run.ps1 b/samples/functionChaining/DurableFunctionsHttpStart/run.ps1 new file mode 100644 index 0000000..94f2bbc --- /dev/null +++ b/samples/functionChaining/DurableFunctionsHttpStart/run.ps1 @@ -0,0 +1,10 @@ +using namespace System.Net + +param($Request, $TriggerMetadata) + +$FunctionName = $Request.Params.FunctionName +$InstanceId = Start-DurableOrchestration -FunctionName $FunctionName -Input "I wrote this in DurableFunctionsHttpStart" +Write-Host "Started orchestration with ID = '$InstanceId'" + +$Response = New-DurableOrchestrationCheckStatusResponse -Request $Request -InstanceId $InstanceId +Push-OutputBinding -Name Response -Value $Response diff --git a/samples/functionChaining/DurableFunctionsOrchestrator/function.json b/samples/functionChaining/DurableFunctionsOrchestrator/function.json new file mode 100644 index 0000000..336f5a1 --- /dev/null +++ b/samples/functionChaining/DurableFunctionsOrchestrator/function.json @@ -0,0 +1,9 @@ +{ + "bindings": [ + { + "name": "Context", + "type": "orchestrationTrigger", + "direction": "in" + } + ] +} \ No newline at end of file diff --git a/samples/functionChaining/DurableFunctionsOrchestrator/run.ps1 b/samples/functionChaining/DurableFunctionsOrchestrator/run.ps1 new file mode 100644 index 0000000..10440d9 --- /dev/null +++ b/samples/functionChaining/DurableFunctionsOrchestrator/run.ps1 @@ -0,0 +1,11 @@ +param($Context) + +$output = @() + +# Function chaining +$output += Invoke-DurableActivity -FunctionName 'Hello' -Input 'Tokyo' +$output += Invoke-DurableActivity -FunctionName 'Hello' -Input 'Seattle' +$output += Invoke-DurableActivity -FunctionName 'Hello' -Input 'London' + +# final expression is the return statement +$output diff --git a/samples/functionChaining/Hello/function.json b/samples/functionChaining/Hello/function.json new file mode 100644 index 0000000..f90ca82 --- /dev/null +++ b/samples/functionChaining/Hello/function.json @@ -0,0 +1,9 @@ +{ + "bindings": [ + { + "name": "name", + "type": "activityTrigger", + "direction": "in" + } + ] +} \ No newline at end of file diff --git a/samples/functionChaining/Hello/run.ps1 b/samples/functionChaining/Hello/run.ps1 new file mode 100644 index 0000000..da627be --- /dev/null +++ b/samples/functionChaining/Hello/run.ps1 @@ -0,0 +1,3 @@ +param($name) + +"Hello $name!" diff --git a/samples/functionChaining/README.md b/samples/functionChaining/README.md new file mode 100644 index 0000000..b02713f --- /dev/null +++ b/samples/functionChaining/README.md @@ -0,0 +1,46 @@ +# Function Chaining sample + +## Pre-requisites + +You'll need core tools version v4.0.5095+. Please run `func --version` to ensure your core tools version is compatible. + +## How to try it out + +This repo already contains the basic project structure for a function-chaining Durable Functions PowerShell app. +You may use this as the starting point for experimentation. + +### 1. Install the SDK from the PowerShell Gallery + +This has been done for you in `requirements.psd1`, by including the following line: + +```json +'AzureFunctions.PowerShell.Durable.SDK' = '1.0.0-alpha' +``` + +### 2. Import the SDK in your `profile.ps1`. + +This has been done for you in this starter project. +Please verify that the `profile.ps1` file contains the following line: + +```powershell +Import-Module AzureFunctions.PowerShell.Durable.SDK -ErrorAction Stop +``` + +### 3. Set the env variable `ExternalDurablePowerShellSDK` to `"true"`. + +This has been done for you in this repo's starter project. +Please verify that this setting is set in your `local.settings.json`. + +### 4. Try it! + +Run `func host start` and run the orchestrator with a GET request to `http://localhost:7071/api/orchestrators/DurableFunctionsOrchestrator`. + +### 6. Confirm you're using the new SDK + +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. + +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. + +## If you deploy to Azure + +You will need to set the `ExternalDurablePowerShellSDK` application setting to `"true"`. \ No newline at end of file diff --git a/samples/functionChaining/host.json b/samples/functionChaining/host.json new file mode 100644 index 0000000..c0a4ab2 --- /dev/null +++ b/samples/functionChaining/host.json @@ -0,0 +1,18 @@ +{ + "version": "2.0", + "logging": { + "applicationInsights": { + "samplingSettings": { + "isEnabled": true, + "excludedTypes": "Request" + } + } + }, + "managedDependency": { + "enabled": true + }, + "extensionBundle": { + "id": "Microsoft.Azure.Functions.ExtensionBundle", + "version": "[3.*, 4.0.0)" + }, +} \ No newline at end of file diff --git a/samples/functionChaining/profile.ps1 b/samples/functionChaining/profile.ps1 new file mode 100644 index 0000000..5b85f02 --- /dev/null +++ b/samples/functionChaining/profile.ps1 @@ -0,0 +1,23 @@ +# 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) { + Disable-AzContextAutosave -Scope Process | Out-Null + 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. +Import-Module AzureFunctions.PowerShell.Durable.SDK -ErrorAction Stop \ No newline at end of file diff --git a/samples/functionChaining/requirements.psd1 b/samples/functionChaining/requirements.psd1 new file mode 100644 index 0000000..aeddd6e --- /dev/null +++ b/samples/functionChaining/requirements.psd1 @@ -0,0 +1,9 @@ +# This file enables modules to be automatically managed by the Functions service. +# See https://aka.ms/functionsmanageddependency for additional information. +# +@{ + # For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. + # To use the Az module in your function app, please uncomment the line below. + # 'Az' = '9.*' + 'AzureFunctions.PowerShell.Durable.SDK' = '1.0.0-alpha' +} \ No newline at end of file