【问题标题】:How to return 202 Accepted and then continue processing the request in Powershell如何返回 202 Accepted 然后继续在 Powershell 中处理请求
【发布时间】:2019-09-01 02:48:30
【问题描述】:

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

我有一个在 azure function app Http Trigger(使用 PowerShell 实验语言)中运行 >3 分钟的脚本。

我正在使用逻辑应用程序实现上述功能,该功能将在 2 分钟后超时。

有没有办法从 PowerShell 返回 202 Accepted 并继续执行脚本。

Tried Out-File(这将在执行完成后触发),返回(破坏应用程序)

【问题讨论】:

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


    【解决方案1】:

    刚刚遇到了类似的问题。调用 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
    

    【讨论】:

    • 这不起作用。 ADF 的 Web Hook Activity 永远不会收到 203。
    【解决方案2】:

    不确定您的问题是否可行,但或者您可以创建Azure Automation run-book 并使用Azure Automation Action 在逻辑应用程序中运行您的 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"
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-20
      • 1970-01-01
      • 2015-12-02
      • 2014-10-06
      • 1970-01-01
      • 2010-12-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多