[英]Azure Function Stops Working After a Few Hours
我有一個 Azure Function 在免費消費應用服務計划上運行。 它使用每 5 分鍾觸發一次的 CRON 計時器 (0 */5 * * * *)。
確認這是消費計划(F1:免費)。
這是一個非常簡單的 function,它使用我的動態 IP 地址更新我的 NSG。
在代碼方面,它每 5 分鍾完美執行一次。 (我確實計划更新腳本,因此它只會在檢測到 IP 已更改時更新)
我面臨的問題是; 如果我讓它去做它的事情,它最終會在一兩個小時后停止。 我已經將主機 function 的空閑時間增加到 10 分鍾。json:
{
"version": "2.0",
"managedDependency": {
"Enabled": true
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[2.*, 3.0.0)"
},
"functionTimeout": "00:10:00"
}
這是 function 的代碼:
# Input bindings are passed in via param block.
param($Timer)
# Get the current universal time in the default string format.
$currentUTCtime = (Get-Date).ToUniversalTime()
# The 'IsPastDue' property is 'true' when the current function invocation is later than scheduled.
if ($Timer.IsPastDue) {
Write-Host "PowerShell timer is running late!"
}
# Write an information log with the current time.
Write-Host "PowerShell timer trigger function started! TIME: $currentUTCtime"
Try{
# Write to the Azure Functions log stream.
Write-Output "PowerShell HTTP trigger function processed a request."
# Interact with query parameters or the body of the request.
Write-Output ($request | ConvertTo-Json -depth 99)
$rawIP = [System.Net.Dns]::GetHostAddresses("MY DYNAMIC IP HOSTNAME")
$ips = $rawIP.IPAddressToString
$nsgName = "NSGNAME"
$resourceGroupName = "resourcegroupname"
$rule_names = @("NSGRULE")
foreach($rule_name in $rule_names)
{
$nsg = Get-AzNetworkSecurityGroup -Name $nsgName -ResourceGroupName $resourceGroupName
$rule= $nsg | Get-AzNetworkSecurityRuleConfig -Name $rule_name
Set-AzNetworkSecurityRuleConfig -NetworkSecurityGroup $nsg `
-Name $rule_name `
-Access $rule.Access `
-Protocol $rule.Protocol `
-Direction $rule.Direction `
-Priority $rule.Priority `
-SourceAddressPrefix $ips `
-SourcePortRange $rule.SourcePortRange `
-DestinationAddressPrefix $rule.DestinationAddressPrefix `
-DestinationPortRange $rule.DestinationPortRange
$nsg | Set-AzNetworkSecurityGroup | out-null
}
}
Catch{
[string]$message += $_
}
我目前的解決方法是在空閑 VM 上打開一個網頁,該網頁使用擴展程序每 2.5 分鍾自動刷新一次……這可以使 function 無限期工作; 我注意到在嘗試對其進行故障排除時有效。
我已經嘗試查看這不起作用的可能原因,但我發現的最好的是超時的增加; 這沒有用。
這是一個鏈接,說明動態功能的服務在應用程序外部。 我明白了,但即使應用程序閑置了,當 CRON 作業計時器被擊中時,它是否應該不會再次觸發?
function 遠沒有達到任何免費配額......每天使用大約 3/60 分鍾的計算,並且僅以 400/1000MB 運行。
我目前沒有啟用任何日志分析,因為 function 是為了省錢; 但如果有人建議我應該打開它來排除故障,我可以。
這篇How come my Azure timer function app stops firing文章似乎暗示如果我重新部署所有資源它可能會起作用; 想避免,但如果沒有來自社區的其他想法被眾包,我會給它一個 go。
由於您在 Azure 功能中使用免費定價層消費計划,即使它在Shared App Service Plan中, Always On支持也不可用。
如果您在基本/標准/高級應用程序服務計划中有 Azure Function 應用程序,則 Always On 默認處於打開狀態,如果關閉,您將在 Azure 門戶的功能用戶界面中收到警告。
如果您在Pay-As-You-Go Consumption Plan中,系統會在指定運行時喚醒您的功能,這是大多數用戶推薦的方法。
另一種小黑客提到搜索引擎是你可以在每個自定義time
(以秒/分鍾為單位) interval
內ping
服務( Function URL)
以防止它空閑state 並且 ping 不計入 CPU 運行時間,除非你 ping不影響時間限制的實際 function URL 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.