Skip to content

Commit 5053bbd

Browse files
authored
Rename Durable commands (#625)
* Rename Invoke-ActivityFunction to Invoke-DurableActivity * Add Invoke-ActivityFunction alias * Use Invoke-DurableActivity in tests and examples * Rename New-OrchestrationCheckStatusResponse to New-DurableOrchestrationCheckStatusResponse * Add alias for New-OrchestrationCheckStatusResponse * Replace New-OrchestrationCheckStatusResponse with New-DurableOrchestrationCheckStatusResponse in tests and examples * Rename Start-NewOrchestration to Start-DurableOrchestration * Add Start-NewOrchestration alias * Replace Start-NewOrchestration with Start-DurableOrchestration in tests and examples * Add E2E test using old command names
1 parent 007a4dd commit 5053bbd

File tree

28 files changed

+176
-57
lines changed

28 files changed

+176
-57
lines changed

docs/designs/PowerShell-AzF-Overall-Design.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -551,17 +551,17 @@ We had a prototype of Durable Functions in PowerShell worker to enable the '_Fun
551551
2. Make the orchestrator function able to be stopped at certain point safely.
552552
3. Make the PowerShell worker able to replay an orchestrator function, namely skipping the actions that are done in previous runs/replays based on the save logs.
553553

554-
They were solved by introducing the new cmdlet "_Invoke-ActivityFunction_" plus having the worker invoke the orchestrator function with the async PowerShell API.
554+
They were solved by introducing the new cmdlet "_Invoke-DurableActivity_" plus having the worker invoke the orchestrator function with the async PowerShell API.
555555

556556
Internally, the worker shares context information with the cmdlet, including _the existing saved logs_ sent from the host about the running orchestrator function and _a wait handler_ - let's call it A - which the cmdlet will set after it triggers an activity function. The async API used to start the orchestrator function returns _another wait handler_ - let's call it B - which will be set when the invocation finishes. Then the invoking thread will call '_WaitHandler.WaitAny_' on those two wait handlers.
557557

558558
- If the call to '_WaitAny_' returns because the wait handler A was set, then that means an activity function was just triggered, and the orchestrator function should be stopped now (it will be triggered again later after the activity function finishes). So, in this case, the invoking thread will stop the orchestrator function that is running asynchronously.
559559
- If the call to '_WaitAny_' returns because the wait handler B was set, then that means the orchestrator function has run to its completion.
560560

561-
The cmdlet '_Invoke-ActivityFunction_' has the following syntax, the '_-FunctionName_' being the name of the activity function to invoke and '_-Input_' being the argument to the activity function.
561+
The cmdlet '_Invoke-DurableActivity_' has the following syntax, the '_-FunctionName_' being the name of the activity function to invoke and '_-Input_' being the argument to the activity function.
562562

563563
```powershell
564-
Invoke-ActivityFunction [-FunctionName] <string> [[-Input] <Object>] [<CommonParameters>]
564+
Invoke-DurableActivity [-FunctionName] <string> [[-Input] <Object>] [<CommonParameters>]
565565
```
566566

567567
When it's invoked to trigger an activity function, it first checks the existing logs shared by the worker to see if this invocation of the activity function has already done previously. If so, the cmdlet simply returns the result. If not, the cmdlet will
@@ -570,7 +570,7 @@ When it's invoked to trigger an activity function, it first checks the existing
570570
- set the wait handler shared by the worker to notify the worker that the activity function is triggered;
571571
- wait on a private wait handler that will only be set when the '_StopProcessing_' method of the cmdlet is called. That method gets called only when the pipeline where this cmdlet is running in is being stopped.
572572

573-
The third step is very important in this stop-and-replay model of Durable Functions, because when stopping an invocation that is running asynchronously, we don't want that to interrupt arbitrary code execution that is happening in the pipeline. By having the cmdlet '_Invoke-ActivityFunction_' wait for '_StopProcessing_' to be called, we know for sure that the pipeline execution pauses at a safe place, ready for being stopped by the invoking thread.
573+
The third step is very important in this stop-and-replay model of Durable Functions, because when stopping an invocation that is running asynchronously, we don't want that to interrupt arbitrary code execution that is happening in the pipeline. By having the cmdlet '_Invoke-DurableActivity_' wait for '_StopProcessing_' to be called, we know for sure that the pipeline execution pauses at a safe place, ready for being stopped by the invoking thread.
574574

575575
The following is an example of PowerShell Durable Function that runs in the Function Chaining pattern:
576576

@@ -583,9 +583,9 @@ param($context)
583583
584584
$output = @()
585585
586-
$output += Invoke-ActivityFunction -FunctionName "E1_SayHello" -Input "Tokyo"
587-
$output += Invoke-ActivityFunction -FunctionName "E1_SayHello" -Input "Seattle"
588-
$output += Invoke-ActivityFunction -FunctionName "E1_SayHello" -Input "London"
586+
$output += Invoke-DurableActivity -FunctionName "E1_SayHello" -Input "Tokyo"
587+
$output += Invoke-DurableActivity -FunctionName "E1_SayHello" -Input "Seattle"
588+
$output += Invoke-DurableActivity -FunctionName "E1_SayHello" -Input "London"
589589
590590
return $output
591591
```

examples/durable/DurableApp/CustomStatusOrchestrator/run.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ Write-Host 'CustomStatusOrchestrator: started.'
77
$output = @()
88

99
Set-DurableCustomStatus -CustomStatus 'Processing Tokyo'
10-
$output += Invoke-ActivityFunction -FunctionName 'SayHello' -Input 'Tokyo'
10+
$output += Invoke-DurableActivity -FunctionName 'SayHello' -Input 'Tokyo'
1111

1212
Set-DurableCustomStatus -CustomStatus @{ ProgressMessage = 'Processing Seattle'; Stage = 2 }
13-
$output += Invoke-ActivityFunction -FunctionName 'SayHello' -Input 'Seattle'
13+
$output += Invoke-DurableActivity -FunctionName 'SayHello' -Input 'Seattle'
1414

1515
Set-DurableCustomStatus -CustomStatus @('Processing London', 'Last stage')
16-
$output += Invoke-ActivityFunction -FunctionName 'SayHello' -Input 'London'
16+
$output += Invoke-DurableActivity -FunctionName 'SayHello' -Input 'London'
1717

1818
Set-DurableCustomStatus 'Processing completed'
1919

examples/durable/DurableApp/FanOutFanInOrchestrator/run.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Write-Host 'FanOutFanInOrchestrator: started.'
66

77
$parallelTasks =
88
foreach ($Name in 'Tokyo', 'Seattle', 'London') {
9-
Invoke-ActivityFunction -FunctionName 'SayHello' -Input $Name -NoWait
9+
Invoke-DurableActivity -FunctionName 'SayHello' -Input $Name -NoWait
1010
}
1111

1212
$output = Wait-DurableTask -Task $parallelTasks

examples/durable/DurableApp/FunctionChainingOrchestrator/run.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Write-Host 'FunctionChainingOrchestrator: started.'
66

77
$output = @()
88

9-
$output += Invoke-ActivityFunction -FunctionName 'SayHello' -Input 'Tokyo'
10-
$output += Invoke-ActivityFunction -FunctionName 'SayHello' -Input 'Seattle'
11-
$output += Invoke-ActivityFunction -FunctionName 'SayHello' -Input 'London'
9+
$output += Invoke-DurableActivity -FunctionName 'SayHello' -Input 'Tokyo'
10+
$output += Invoke-DurableActivity -FunctionName 'SayHello' -Input 'Seattle'
11+
$output += Invoke-DurableActivity -FunctionName 'SayHello' -Input 'London'
1212

1313
Write-Host 'FunctionChainingOrchestrator: finished.'
1414

examples/durable/DurableApp/FunctionChainingWithRetriesOrchestrator/run.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ $retryOptions = New-DurableRetryOptions `
1010
-FirstRetryInterval (New-Timespan -Seconds 1) `
1111
-MaxNumberOfAttempts 7
1212

13-
$output += Invoke-ActivityFunction -FunctionName 'FlakyActivity' -Input 'Tokyo' -RetryOptions $retryOptions
14-
$output += Invoke-ActivityFunction -FunctionName 'FlakyActivity' -Input 'Seattle' -RetryOptions $retryOptions
15-
$output += Invoke-ActivityFunction -FunctionName 'FlakyActivity' -Input 'London' -RetryOptions $retryOptions
13+
$output += Invoke-DurableActivity -FunctionName 'FlakyActivity' -Input 'Tokyo' -RetryOptions $retryOptions
14+
$output += Invoke-DurableActivity -FunctionName 'FlakyActivity' -Input 'Seattle' -RetryOptions $retryOptions
15+
$output += Invoke-DurableActivity -FunctionName 'FlakyActivity' -Input 'London' -RetryOptions $retryOptions
1616

1717
$output

examples/durable/DurableApp/HttpStart/run.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ param($Request, $TriggerMetadata)
44

55
Write-Host 'HttpStart started'
66

7-
$InstanceId = Start-NewOrchestration -FunctionName $Request.Params.FunctionName -InputObject $Request.Query.Input
7+
$InstanceId = Start-DurableOrchestration -FunctionName $Request.Params.FunctionName -InputObject $Request.Query.Input
88
Write-Host "Started orchestration $($Request.Params.FunctionName) with ID = '$InstanceId'"
99

10-
$Response = New-OrchestrationCheckStatusResponse -Request $Request -InstanceId $InstanceId
10+
$Response = New-DurableOrchestrationCheckStatusResponse -Request $Request -InstanceId $InstanceId
1111
Push-OutputBinding -Name Response -Value $Response
1212

1313
Write-Host 'HttpStart completed'

examples/durable/DurableApp/HumanInteractionOrchestrator/run.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ $duration = New-TimeSpan -Seconds $Context.Input.Duration
1010
$managerId = $Context.Input.ManagerId
1111
$skipManagerId = $Context.Input.SkipManagerId
1212

13-
$output += Invoke-ActivityFunction -FunctionName "RequestApproval" -Input $managerId
13+
$output += Invoke-DurableActivity -FunctionName "RequestApproval" -Input $managerId
1414

1515
$durableTimeoutEvent = Start-DurableTimer -Duration $duration -NoWait
1616
$approvalEvent = Start-DurableExternalEventListener -EventName "ApprovalEvent" -NoWait
@@ -19,10 +19,10 @@ $firstEvent = Wait-DurableTask -Task @($approvalEvent, $durableTimeoutEvent) -An
1919

2020
if ($approvalEvent -eq $firstEvent) {
2121
Stop-DurableTimerTask -Task $durableTimeoutEvent
22-
$output += Invoke-ActivityFunction -FunctionName "ProcessApproval" -Input $approvalEvent
22+
$output += Invoke-DurableActivity -FunctionName "ProcessApproval" -Input $approvalEvent
2323
}
2424
else {
25-
$output += Invoke-ActivityFunction -FunctionName "EscalateApproval" -Input $skipManagerId
25+
$output += Invoke-DurableActivity -FunctionName "EscalateApproval" -Input $skipManagerId
2626
}
2727

2828
Write-Host 'HumanInteractionOrchestrator: finished.'

examples/durable/DurableApp/HumanInteractionStart/run.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Write-Host 'HumanInteractionStart started'
66

77
$OrchestratorInputs = @{ Duration = 45; ManagerId = 1; SkipManagerId = 2 }
88

9-
$InstanceId = Start-NewOrchestration -FunctionName 'HumanInteractionOrchestrator' -InputObject $OrchestratorInputs
9+
$InstanceId = Start-DurableOrchestration -FunctionName 'HumanInteractionOrchestrator' -InputObject $OrchestratorInputs
1010
Write-Host "Started orchestration with ID = '$InstanceId'"
1111

12-
$Response = New-OrchestrationCheckStatusResponse -Request $Request -InstanceId $InstanceId
12+
$Response = New-DurableOrchestrationCheckStatusResponse -Request $Request -InstanceId $InstanceId
1313
Push-OutputBinding -Name Response -Value $Response
1414

1515
Write-Host 'HumanInteractionStart completed'

examples/durable/DurableApp/MonitorOrchestrator/run.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ $pollingInterval = New-TimeSpan -Seconds $Context.Input.PollingInterval
1212
$expiryTime = $Context.Input.ExpiryTime
1313

1414
while ($Context.CurrentUtcDateTime -lt $expiryTime) {
15-
$jobStatus = Invoke-ActivityFunction -FunctionName 'GetJobStatus' -Input $jobId
15+
$jobStatus = Invoke-DurableActivity -FunctionName 'GetJobStatus' -Input $jobId
1616
if ($jobStatus -eq "Completed") {
1717
# Perform an action when a condition is met.
18-
$output += Invoke-ActivityFunction -FunctionName 'SendAlert' -Input $machineId
18+
$output += Invoke-DurableActivity -FunctionName 'SendAlert' -Input $machineId
1919
break
2020
}
2121

examples/durable/DurableApp/MonitorStart/run.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Write-Host 'MonitorStart started'
66

77
$OrchestratorInputs = @{ JobId = 1; MachineId = 1; PollingInterval = 10; ExpiryTime = (Get-Date).ToUniversalTime().AddSeconds(60) }
88

9-
$InstanceId = Start-NewOrchestration -FunctionName 'MonitorOrchestrator' -InputObject $OrchestratorInputs
9+
$InstanceId = Start-DurableOrchestration -FunctionName 'MonitorOrchestrator' -InputObject $OrchestratorInputs
1010
Write-Host "Started orchestration with ID = '$InstanceId'"
1111

12-
$Response = New-OrchestrationCheckStatusResponse -Request $Request -InstanceId $InstanceId
12+
$Response = New-DurableOrchestrationCheckStatusResponse -Request $Request -InstanceId $InstanceId
1313
Push-OutputBinding -Name Response -Value $Response
1414

1515
Write-Host 'MonitorStart completed'

0 commit comments

Comments
 (0)