3

How to return 202 Accepted and then continue processing the request in PowerShell.

I have a script that runs >3 minutes in azure function app Http Trigger(using PowerShell experimental language).

I'm hitting above function using logic app which will timeout in 2 minutes.

Is there a way to return 202 Accepted from PowerShell and continue executing the script.

Tried Out-File (This will fire after complete execution), return (Breaks the application)

VIJAY RAAVI
  • 388
  • 3
  • 11

2 Answers2

1

Just ran into a similar issue. Client calling the Azure Function is getting an HTTP Response 503. Looks to be from Azure hard limit of 230 second HTTP Response Timeout. Try sending HTTP Response 202 ACCEPTED from your Azure Function using the response output binding PowerShell cmdlet Push-OutputBinding.

Reference: https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-powershell#bindings

 Push-OutputBinding -Name response -Value ([HttpResponseContext]@{
            StatusCode = [System.Net.HttpStatusCode]::Accepted
            Body = "Process Started"
        }) -Clobber
0

Not sure if your ask is feasible but Alternatively you can create Azure Automation run-book and run you PS script within the Logic App using Azure Automation Action.

{
    "$connections": {
        "value": {
            "azureautomation": {
                "connectionId": "/subscriptions/<SubscriptionId>/resourceGroups/<ResourceGroup>/providers/Microsoft.Web/connections/azureautomation",
                "connectionName": "azureautomation",
                "id": "/subscriptions/<SubscriptionId>/providers/Microsoft.Web/locations/southeastasia/managedApis/azureautomation"
            }
        }
    },
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Create_job": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureautomation']['connectionId']"
                        }
                    },
                    "method": "put",
                    "path": "/subscriptions/@{encodeURIComponent('<SubscriptionId>')}/resourceGroups/@{encodeURIComponent('ResourceGroup')}/providers/Microsoft.Automation/automationAccounts/@{encodeURIComponent('<AutomationAccount>')}/jobs/",
                    "queries": {
                        "runbookName": "test",
                        "wait": true,
                        "x-ms-api-version": "2015-10-31"
                    }
                },
                "runAfter": {},
                "type": "ApiConnection"
            },
            "Get_job_output": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureautomation']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/subscriptions/@{encodeURIComponent('<SubscriptionId>')}/resourceGroups/@{encodeURIComponent('ResourceGroup')}/providers/Microsoft.Automation/automationAccounts/@{encodeURIComponent('<AutomationAccount>')}/jobs/@{encodeURIComponent(body('Create_job')?['properties']?['jobId'])}/output",
                    "queries": {
                        "x-ms-api-version": "2015-10-31"
                    }
                },
                "runAfter": {
                    "Create_job": [
                        "Succeeded"
                    ]
                },
                "type": "ApiConnection"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    }
}

enter image description here

Ketan
  • 1,530
  • 7
  • 16