如何返回202 Accepted,然后继续在Powershell中处理请求

时间:2019-04-10 15:13:52

标签: function powershell azure-functions azure-logic-apps azure-function-async

如何返回202已接受,然后继续在PowerShell中处理请求。

我有一个脚本,在azure函数应用Http触发器(使用PowerShell实验语言)中运行了3分钟以上。

我正在使用逻辑应用程序执行上述功能,该应用程序将在2分钟内超时。

是否可以从PowerShell返回202接受并继续执行脚本。

尝试输出文件(此文件将在完全执行后触发),返回(破坏应用程序)

2 个答案:

答案 0 :(得分:0)

不确定您的要求是否可行,但也可以创建Azure Automation run-book并使用Azure Automation Action在Logic App中运行PS脚本。

{
    "$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

答案 1 :(得分:0)

遇到了类似的问题。调用Azure函数的客户端收到HTTP响应503。看起来是来自230秒HTTP响应超时的Azure硬限制。尝试使用响应输出绑定PowerShell cmdlet Push-OutputBinding从Azure函数发送HTTP响应202 ACCEPTED。

参考:https://docs.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