Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,15 @@ StyleCop.Cache

examples/PSCoreApp/Modules
src/Modules
!src/Modules/Microsoft.AzureFunctions.PowerShellWorker
!src/Modules/Microsoft.Azure.Functions.PowerShellWorker

# protobuf
protobuf/*
src/Messaging/protobuf

# pulled in for tests
Azure.Functions.Cli

# Azure Functions artifacts
appsettings.json
local.settings.json
3 changes: 3 additions & 0 deletions examples/durable/FunctionChainingApp/.funcignore
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 examples/durable/FunctionChainingApp/HttpTrigger/function.json
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"
}
]
}
17 changes: 17 additions & 0 deletions examples/durable/FunctionChainingApp/HttpTrigger/run.ps1
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"
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 examples/durable/FunctionChainingApp/MyOrchestrator/run.ps1
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
9 changes: 9 additions & 0 deletions examples/durable/FunctionChainingApp/SayHello/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"bindings": [
{
"name": "name",
"type": "activityTrigger",
"direction": "in"
}
]
}
6 changes: 6 additions & 0 deletions examples/durable/FunctionChainingApp/SayHello/run.ps1
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"
11 changes: 11 additions & 0 deletions examples/durable/FunctionChainingApp/extensions.csproj
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>
3 changes: 3 additions & 0 deletions examples/durable/FunctionChainingApp/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "2.0"
}
21 changes: 21 additions & 0 deletions examples/durable/FunctionChainingApp/profile.ps1
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.
4 changes: 4 additions & 0 deletions examples/durable/FunctionChainingApp/proxies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {}
}
3 changes: 3 additions & 0 deletions examples/durable/LongRunningHttpApp/.funcignore
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 examples/durable/LongRunningHttpApp/HttpTrigger/function.json
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"
}
]
}
18 changes: 18 additions & 0 deletions examples/durable/LongRunningHttpApp/HttpTrigger/run.ps1
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"
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 examples/durable/LongRunningHttpApp/LongRunningActivity/run.ps1
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"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"bindings": [
{
"name": "Context",
"type": "orchestrationTrigger",
"direction": "in"
}
]
}
9 changes: 9 additions & 0 deletions examples/durable/LongRunningHttpApp/MyOrchestrator/run.ps1
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
11 changes: 11 additions & 0 deletions examples/durable/LongRunningHttpApp/extensions.csproj
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>
4 changes: 4 additions & 0 deletions examples/durable/LongRunningHttpApp/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"version": "2.0",
"functionTimeout": "02:00:00"
}
21 changes: 21 additions & 0 deletions examples/durable/LongRunningHttpApp/profile.ps1
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.
4 changes: 4 additions & 0 deletions examples/durable/LongRunningHttpApp/proxies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {}
}
48 changes: 48 additions & 0 deletions src/Durable/ActionType.cs
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,
}
}
30 changes: 30 additions & 0 deletions src/Durable/CallActivityAction.cs
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;
}
}
}
Loading