Azure函数应用程序powershell触发两次/三次
我收到一个Azure警报,其中包含一个包含我的Azure功能应用程序的操作组Azure函数应用程序powershell触发两次/三次,azure,powershell,azure-functions,Azure,Powershell,Azure Functions,我收到一个Azure警报,其中包含一个包含我的Azure功能应用程序的操作组 功能应用程序在消费计划中 但是,当触发1个警报时,我会收到两个,有时是三个功能应用程序回复。目前正在通过电子邮件进行测试,但可以是团队/Slack/Twilio或其他方式 我已经检查了我的代码好几次,但找不到它为什么运行了好几次。 这可能是冷启动问题吗? 我不应该点击超时,因为它会在几秒钟内完成 我需要下面的代码块吗 Push-OutputBinding -Name Response -Value ([HttpResp
功能应用程序在消费计划中
但是,当触发1个警报时,我会收到两个,有时是三个功能应用程序回复。目前正在通过电子邮件进行测试,但可以是团队/Slack/Twilio或其他方式
我已经检查了我的代码好几次,但找不到它为什么运行了好几次。
这可能是冷启动问题吗?
我不应该点击超时,因为它会在几秒钟内完成
我需要下面的代码块吗
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = $status
})
例如,2019年11月14日上午4:59:02触发的警报功能应用程序生成了三个回复:
- 05:00
- 05:00
- 05:01
好的,在Azure支持的长期案例之后,这里有一个更新。如果有人到这里来 使用Azure应用程序功能的Azure警报操作组的核心是webhook调用。这意味着它具有与常规webhook相同的限制/约束。 看 10秒后重试,100秒后再次重试。如果在消费时使用Azure应用程序功能,应用程序功能冷启动可能需要更长的时间。这意味着它最多可以被调用三次,因为每次调用应用程序功能时,应用程序功能都会运行,即使冷启动功能需要时间(有时启动速度更快,您只能运行两次,如果它已经运行,您可以运行一次) 取决于你在做什么,这可能是个问题。Azure支持人员在中提出的建议以粗体显示,另一个是我可能的解决方案(请注意,我的建议将产生成本)
- 使函数幂等
- 使函数有状态
- 使用始终打开的应用程序服务计划
- 使用逻辑应用程序
- 如果Powershell使用自动化帐户运行手册
using namespace System.Net
using namespace System.Web
# Input bindings are passed in via param block.
param($Request)
# Write to the Azure Functions log stream.
$alert = $Request.RawBody | convertfrom-json
function New-TypeTable([object[]]$columns)
{
$hash = [ordered]@{}
foreach ($c in $columns)
{
switch ($c.type)
{
"datetime" { $type = [datetime] }
"real" { $type = [decimal] }
default { $type = [string] }
}
$hash.Add($c.name, $type)
}
$hash
}
function Set-Culture([System.Globalization.CultureInfo] $culture)
{
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
[System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
}
#Set locale to swedish for datetime
Set-Culture sv-SE
#Set variables for later use
$alertRule = $alert.data.essentials.alertRule
$alertDescription = $alert.data.essentials.description
$tables = $alert.data.alertContext.SearchResults.tables
foreach ($table in $tables)
{
$cHash = New-TypeTable -columns $table.columns
[string[]]$keys = $cHash.Keys
$tableInfo = foreach ($row in $table.rows)
{
$psObj = New-Object PSObject
for ($i = 0; $i -lt $row.Count; $i++)
{
$value = $row[$i]
$type = $cHash[$i]
#Round the value of AggregatedValue and CounterValue
if ($keys[$i] -eq "AggregatedValue" -Or $keys[$i] -eq "CounterValue") {
$value = [math]::Round($value,1)
}
#Set the value of TimeGenerated to a specific format
if ($keys[$i] -eq "TimeGenerated") {
$value = "{0:yyyy-MM-dd HH:mm:ss}" -f $value
}
#Don't add Null values
if($value) {
$psObj | Add-Member -MemberType NoteProperty -Name $keys[$i] -Value ($value -as $type)
}
}
$psObj
}
}
#Write-Information $tableInfo -verbose
$Header = @"
<style>
TABLE {width: 750px; border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}
TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black; background-color: #6495ED;}
TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}
</style>
"@
#Create HTML-table from the object
$Body = $tableInfo | ConvertTo-Html -head $Header
DATE (UTC) SUCCESS RESULT CODE DURATION (MS)
2019-11-18 20:31:16.092 204 799.4648
2019-11-18 20:29:32.032 204 23197.282
2019-11-18 20:29:17.956 204 41919.4075