如何返回 202 Accepted 然后继续在 PowerShell 中处理请求。
我有一个在 azure function app Http Trigger(使用 PowerShell 实验语言)中运行 > 3 分钟的脚本。
我正在使用逻辑应用程序实现上述功能,该应用程序将在 2 分钟内超时。
有没有办法从 PowerShell 返回 202 Accepted 并继续执行脚本。
Tried Out-File(这将在完成执行后触发),返回(破坏应用程序)
如何返回 202 Accepted 然后继续在 PowerShell 中处理请求。
我有一个在 azure function app Http Trigger(使用 PowerShell 实验语言)中运行 > 3 分钟的脚本。
我正在使用逻辑应用程序实现上述功能,该应用程序将在 2 分钟内超时。
有没有办法从 PowerShell 返回 202 Accepted 并继续执行脚本。
Tried Out-File(这将在完成执行后触发),返回(破坏应用程序)
刚刚遇到了类似的问题。调用 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
不确定您的要求是否可行,但或者您可以创建Azure 自动化运行手册并使用Azure 自动化操作在逻辑应用程序中运行您的 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"
}
}
}
}