简体   繁体   English

Azure Function 几个小时后停止工作

[英]Azure Function Stops Working After a Few Hours

I have an Azure Function running on a free consumption App Service Plan.我有一个 Azure Function 在免费消费应用服务计划上运行。 It uses a CRON timer that triggers every 5 minutes (0 */5 * * * *).它使用每 5 分钟触发一次的 CRON 计时器 (0 */5 * * * *)。

To confirm this is on a consumption plan (F1: Free).确认这是消费计划(F1:免费)。

It is a very simple function that updates my NSG with my Dynamic IP address.这是一个非常简单的 function,它使用我的动态 IP 地址更新我的 NSG。

Code wise it executes perfectly every 5 minutes.在代码方面,它每 5 分钟完美执行一次。 (I do plan to update the script so it will only update if it detects the IP has changed) (我确实计划更新脚本,因此它只会在检测到 IP 已更改时更新)

The issue I'm facing is;我面临的问题是; If I leave it to do it's thing, it eventually stops after an hour or two.如果我让它去做它的事情,它最终会在一两个小时后停止。 I've increased the idle time for the function to 10 minutes in the host.json:我已经将主机 function 的空闲时间增加到 10 分钟。json:

{
  "version": "2.0",
  "managedDependency": {
    "Enabled": true
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
  },
  "functionTimeout": "00:10:00"
}

Here is the code for the function:这是 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 += $_
}

The workaround I have at the moment is to have a webpage open on an idle VM that auto-refreshes every 2.5 minutes using an extension... This keeps the function working indefinitely;我目前的解决方法是在空闲 VM 上打开一个网页,该网页使用扩展程序每 2.5 分钟自动刷新一次……这可以使 function 无限期工作; which I noticed worked when trying to troubleshoot it.我注意到在尝试对其进行故障排除时有效。

I've tried looking at possible reasons this isn't working but the best I have found was the increase in timeout;我已经尝试查看这不起作用的可能原因,但我发现的最好的是超时的增加; which hasn't worked.这没有用。

Here is a link explaining that the service for dynamic functions is external to the app.这是一个链接,说明动态功能的服务在应用程序外部。 I get that but even if the app idles out should it not trigger again when the CRON job timer is hit?我明白了,但即使应用程序闲置了,当 CRON 作业计时器被击中时,它是否应该不会再次触发?

The function does NOT hit any free quotas by a long shot... uses about 3/60 minutes compute a day and only runs at 400/1000MB. function 远没有达到任何免费配额......每天使用大约 3/60 分钟的计算,并且仅以 400/1000MB 运行。

I do not have any log analytics enabled at the moment as the function is meant to save me money;我目前没有启用任何日志分析,因为 function 是为了省钱; but if anyone suggests I should turn it on to troubleshoot I can.但如果有人建议我应该打开它来排除故障,我可以。

This How come my Azure timer function app stops firing article seems to suggest it might work if I redeploy all the resources;这篇How come my Azure timer function app stops firing文章似乎暗示如果我重新部署所有资源它可能会起作用; would like to avoid but if no other ideas from the community is crowdsourced I will give it a go.想避免,但如果没有来自社区的其他想法被众包,我会给它一个 go。

As you're using the Free Pricing Tier Consumption Plan in Azure Functions and even if it is in Shared App Service Plan , Always On support is not available.由于您在 Azure 功能中使用免费定价层消费计划,即使它在Shared App Service Plan中, Always On支持也不可用。

  • If you have an Azure Function App in a Basic/Standard/Premium App Service Plan , Always On is on by default and if it is turn off, you'll get a warning in the Functions User Interface of the Azure Portal.如果您在基本/标准/高级应用程序服务计划中有 Azure Function 应用程序,则 Always On 默认处于打开状态,如果关闭,您将在 Azure 门户的功能用户界面中收到警告。

  • If you are in Pay-As-You-Go Consumption Plan , the system takes Care of waking up your functions whenever they are specified to run, which is the recommended approach for most of the users.如果您在Pay-As-You-Go Consumption Plan中,系统会在指定运行时唤醒您的功能,这是大多数用户推荐的方法

  • Alternative small hack mentioned the search engine is that you can ping the service ( Function URL) every custom time (in seconds/minutes) interval which prevents it from being idle state and that pinging doesn't count towards the CPU run time unless you ping the actual function URL which doesn't affect the time limit .另一种小黑客提到搜索引擎是你可以在每个自定义time (以秒/分钟为单位) intervalping服务Function URL)以防止它空闲state 并且 ping 不计入 CPU 运行时间,除非你 ping不影响时间限制的实际 function URL 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 自托管集成运行时在可变运行时间后停止工作 - Self-hosted Integration Runtime stops working after variable hours running 依赖跟踪在 azure function 应用程序部署后不起作用 - Dependency tracking is not working after azure function app deployment Firebase Function 间隔 10 分钟后停止 - Firebase Function stops interval after 10 min Azure 时间跳虎 function 不工作 - Azure time tigger function is not working Azure function RSA 解密代码不起作用 - Azure function RSA decrypt code not working 如何安排 lambda function 在另一个 lambda function 记录特定条目后运行 2 小时? - How to schedule a lambda function to run 2 hours after another lambda function logs a specific entry? Azure function CORS 配置 SignalR 服务不工作 - Azure function CORS configuration with SignalR Service not working 在 google cloud composer 2.0.1 上更新 pypi 包后,airflow 调度程序停止工作 - The airflow scheduler stops working after updating pypi packages on google cloud composer 2.0.1 为什么 firestore 在云 function 成功完成后几分钟更新文档? - why firestore updates the document few minutes after successful cloud function completion? 延迟数小时调用 lambda function - invoke lambda function with hours delay
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM