Skip to content

Commit

Permalink
feat: Introduce MaximumFollowNextPageLink option for usage with `Get-…
Browse files Browse the repository at this point in the history
…AzLogicAppRunHistory` (#396)

Co-authored-by: Stijn Moreels <[email protected]>
Co-authored-by: Pim Simons <[email protected]>
  • Loading branch information
3 people authored Jul 3, 2023
1 parent e014395 commit 1b281cb
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 52 deletions.
81 changes: 41 additions & 40 deletions docs/preview/03-Features/powershell/azure-logic-apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ PS> Install-Module -Name Arcus.Scripting.LogicApps

Use this script to cancel all running instances for a specific Azure Logic App.

| Parameter | Mandatory | Description |
| ------------------- | --------- | -------------------------------------------------- |
| `ResourceGroupName` | yes | The resource group containing the Azure Logic App. |
| `LogicAppName` | yes | The name of the Azure Logic App to be disabled. |
| Parameter | Mandatory | Description |
| --------------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ResourceGroupName` | yes | The resource group containing the Azure Logic App. |
| `LogicAppName` | yes | The name of the Azure Logic App for which the runs will be cancelled. |
| `MaximumFollowNextPageLink` | no | This sets the amount of pages (30 runs per page) of the Logic App run history (if any) that are retrieved. If not supplied the default value is 10. |

**Example**

Expand All @@ -37,12 +38,13 @@ PS> Cancel-AzLogicAppRuns `

Use this script to re-run a failed Azure Logic App run.

| Parameter | Mandatory | Description |
| ------------------- | --------- | ---------------------------------------------------------------------------------------------------------- |
| `ResourceGroupName` | yes | The resource group containing the Azure Logic App. |
| `LogicAppName` | yes | The name of the Azure Logic App to be disabled. |
| `StartTime` | yes | The start time in UTC for retrieving the failed instances. |
| `EndTime` | no | The end time in UTC for retrieving the failed instances, if not supplied it will use the current datetime. |
| Parameter | Mandatory | Description |
| --------------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ResourceGroupName` | yes | The resource group containing the Azure Logic App. |
| `LogicAppName` | yes | The name of the Azure Logic App for which the failed runs will be resubmitted. |
| `StartTime` | yes | The start time in UTC for retrieving the failed instances. |
| `EndTime` | no | The end time in UTC for retrieving the failed instances, if not supplied it will use the current datetime. |
| `MaximumFollowNextPageLink` | no | This sets the amount of pages (30 runs per page) of the Logic App run history (if any) that are retrieved. If not supplied the default value is 10. |

**Example**

Expand Down Expand Up @@ -147,25 +149,25 @@ Typically done the first task of the release pipeline, right before the deployme
The Azure Logic Apps to be disabled and the order in which this will be done, will be defined in the provided configuration file.
The order of the Azure Logic Apps in the configuration file (bottom to top) defines the order in which they will be disabled by the script. The counterpart of this script used to enable the Azure Logic Apps, will take the order as specified (top to bottom) in the file.

| Parameter | Mandatory | Description |
| ----------------- | --------- | ------------------------------------------------------------------------------------------------------------------- |
| ResourceGroupName | yes | The resource group containing the Azure Logic Apps. |
| DeployFileName | no | If your solution consists of multiple interfaces, you can specify the flow-specific name of the configuration file. |
| ResourcePrefix | no | In case the Azure Logic Apps all start with the same prefix, you can specify this prefix through this parameter |
| | | instead of updating the configuration-file. |
| EnvironmentName | no | The name of the Azure environment where the Azure Logic App resides. (default: `AzureCloud`) |
| ApiVersion | no | The version of the management API to be used. (default: `2016-06-01`) |
| Parameter | Mandatory | Description |
| ----------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ResourceGroupName | yes | The resource group containing the Azure Logic Apps. |
| DeployFileName | no | If your solution consists of multiple interfaces, you can specify the flow-specific name of the configuration file. |
| ResourcePrefix | no | In case the Azure Logic Apps all start with the same prefix, you can specify this prefix through this parameter instead of updating the configuration-file. |
| EnvironmentName | no | The name of the Azure environment where the Azure Logic App resides. (default: `AzureCloud`) |
| ApiVersion | no | The version of the management API to be used. (default: `2016-06-01`) |

The schema of this configuration file is a JSON structure of an array with the following inputs:

| Node | Type | Description |
| ----------- | --------------- | --------------------------------------------------------------------------------------------------------------------- |
| Description | `string` | Description of Azure Logic App set to disable. |
| CheckType | `enum` | `None`: don't perform any additional checks. |
| | | `NoWaitingOrRunningRuns`: waits until there are no more waiting or running Logic App instances. |
| StopType | `enum` | `None`: don't disable to given Logic Apps. |
| | | `Immediate`: disable the given Logic Apps. |
| LogicApps | `string array` | Set of Logic App names to disable. |
| Node | Type | Description |
| ------------------------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| Description | `string` | Description of Azure Logic App set to disable. |
| MaximumFollowNextPageLink | `integer` | This sets the amount of pages (30 runs per page) of the Logic App run history (if any) that are retrieved. If not supplied the default value is 10. |
| CheckType | `enum` | `None`: don't perform any additional checks. |
| | | `NoWaitingOrRunningRuns`: waits until there are no more waiting or running Logic App instances. |
| StopType | `enum` | `None`: don't disable to given Logic Apps. |
| | | `Immediate`: disable the given Logic Apps. |
| LogicApps | `string array` | Set of Logic App names to disable. |

**Example**

Expand All @@ -177,6 +179,7 @@ Taking an example in which a set of Azure Logic Apps (`"rcv-shopping-order-*"`)
"description": "Sender(s)",
"checkType": "None",
"stopType": "Immediate",
"maximumFollowNextPageLink": 25,
"logicApps": [
"snd-shopping-order-confirmation-smtp"
]
Expand Down Expand Up @@ -293,25 +296,23 @@ Typically done as the last task of the release pipeline, right after the deploym
The Azure Logic Apps to be enabled and the order in which this will be done, will be defined in the provided configuration file.
The order of the Azure Logic Apps in the configuration file (top to bottom) defines the order in which they will be enabled by the script. The counterpart of this script used to disable the Azure Logic Apps, will take the reversed order as specified (bottom to top) in the file.

| Parameter | Mandatory | Description |
| ----------------- | --------- | ------------------------------------------------------------------------------------------------------------------- |
| ResourceGroupName | yes | The resource group containing the Azure Logic Apps. |
| DeployFileName | no | If your solution consists of multiple interfaces, you can specify the flow-specific name of the configuration file. |
| ResourcePrefix | no | In case the Azure Logic Apps all start with the same prefix, you can specify this prefix through this parameter |
| | | instead of updating the configuration-file. |
| EnvironmentName | no | The name of the Azure environment where the Azure Logic App resides. (default: `AzureCloud`) |
| ApiVersion | no | The version of the management API to be used. (default: `2016-06-01`) |
| Parameter | Mandatory | Description |
| ----------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ResourceGroupName | yes | The resource group containing the Azure Logic Apps. |
| DeployFileName | no | If your solution consists of multiple interfaces, you can specify the flow-specific name of the configuration file. |
| ResourcePrefix | no | In case the Azure Logic Apps all start with the same prefix, you can specify this prefix through this parameter instead of updating the configuration-file. |
| EnvironmentName | no | The name of the Azure environment where the Azure Logic App resides. (default: `AzureCloud`) |
| ApiVersion | no | The version of the management API to be used. (default: `2016-06-01`) |

The schema of this configuration file is a JSON structure of an array with the following inputs:

| Node | Type | Description |
| ----------- | --------------- | --------------------------------------------------------------------------------------------------------------------- |
| Description | `string` | Description of Azure Logic App set to enable. |
| CheckType | `enum` | _Not taken into account for enabling Logic Apps._ |
| StopType | `enum` | `None`: don't enable to given Logic Apps. |
| | | `Immediate`: enable the given Logic Apps. |
| LogicApps | `string array` | Set of Logic App names to enable. |

| Description | `string` | Description of Azure Logic App set to enable. |
| CheckType | `enum` | _Not taken into account for enabling Logic Apps._ |
| StopType | `enum` | `None`: don't enable to given Logic Apps. |
| | | `Immediate`: enable the given Logic Apps. |
| LogicApps | `string array` | Set of Logic App names to enable. |
**Example**

Taking an example in which a set of Azure Logic Apps (`"rcv-shopping-order-*"`) need to be enabled, the following configuration will ignore the `checkType`, as this is only used for disabling the Logic Apps, and will simply enable them (`stopType = Immediate`), starting with the _sender_ instances and working its way down to the _receive protocol_ Logic Apps.
Expand Down
18 changes: 13 additions & 5 deletions src/Arcus.Scripting.LogicApps/Arcus.Scripting.LogicApps.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@
.Parameter LogicAppName
The name of the Azure Logic App.
.Parameter MaximumFollowNextPageLink
The number of times the script should retrieve the next page of Logic App runs, if not specified the entire run history of the Logic App will be retrieved.
#>
function Cancel-AzLogicAppRuns {
param(
[Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Name of the resource group is required"),
[Parameter(Mandatory = $true)][string] $LogicAppName = $(throw "Name of the logic app is required")
[Parameter(Mandatory = $true)][string] $LogicAppName = $(throw "Name of the logic app is required"),
[Parameter(Mandatory = $false)][int] $MaximumFollowNextPageLink = 10
)

. $PSScriptRoot\Scripts\Cancel-AzLogicAppRuns.ps1 -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName
. $PSScriptRoot\Scripts\Cancel-AzLogicAppRuns.ps1 -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -MaximumFollowNextPageLink $MaximumFollowNextPageLink
}

Export-ModuleMember -Function Cancel-AzLogicAppRuns
Expand All @@ -42,19 +46,23 @@ Export-ModuleMember -Function Cancel-AzLogicAppRuns
.Parameter EndTime
The end time of the failed instances of the Azure Logic App.
.Parameter MaximumFollowNextPageLink
The number of times the script should retrieve the next page of Logic App runs, if not specified the entire run history of the Logic App will be retrieved.
#>
function Resubmit-FailedAzLogicAppRuns {
param(
[Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Name of the resource group is required"),
[Parameter(Mandatory = $true)][string] $LogicAppName = $(throw "Name of the logic app is required"),
[Parameter(Mandatory = $true)][datetime] $StartTime = $(throw "Start time is required"),
[Parameter(Mandatory = $false)][datetime] $EndTime
[Parameter(Mandatory = $false)][datetime] $EndTime,
[Parameter(Mandatory = $false)][int] $MaximumFollowNextPageLink = 10
)

if ($EndTime) {
. $PSScriptRoot\Scripts\Resubmit-FailedAzLogicAppRuns.ps1 -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -StartTime $StartTime -EndTime $EndTime
. $PSScriptRoot\Scripts\Resubmit-FailedAzLogicAppRuns.ps1 -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -StartTime $StartTime -EndTime $EndTime -MaximumFollowNextPageLink $MaximumFollowNextPageLink
} else {
. $PSScriptRoot\Scripts\Resubmit-FailedAzLogicAppRuns.ps1 -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -StartTime $StartTime
. $PSScriptRoot\Scripts\Resubmit-FailedAzLogicAppRuns.ps1 -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -StartTime $StartTime -MaximumFollowNextPageLink $MaximumFollowNextPageLink
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
param(
[Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Name of the resource group is required"),
[Parameter(Mandatory = $true)][string] $LogicAppName = $(throw "Name of the logic app is required")
[Parameter(Mandatory = $true)][string] $LogicAppName = $(throw "Name of the logic app is required"),
[Parameter(Mandatory = $false)][int] $MaximumFollowNextPageLink = 10
)

try {
$runs = Get-AzLogicAppRunHistory -ResourceGroupName $ResourceGroupName -Name $LogicAppName -FollowNextPageLink |
$runs = Get-AzLogicAppRunHistory -ResourceGroupName $ResourceGroupName -Name $LogicAppName -FollowNextPageLink -MaximumFollowNextPageLink $MaximumFollowNextPageLink |
Where-Object {$_.Status -eq 'Running'}

foreach ($run in $runs) {
Expand Down
Loading

0 comments on commit 1b281cb

Please sign in to comment.