gpt4 book ai didi

azure - 有没有办法以编程方式重新启动 azure 函数

转载 作者:行者123 更新时间:2023-12-03 16:13:59 31 4
gpt4 key购买 nike

我有一个 Azure 函数每隔几分钟在计时器上运行一次,在运行不同时间后,由于外部 API,每次运行都会开始失败,并且在 Azure 门户中手动单击重新启动按钮修复了问题然后工作又开始工作了。

有没有办法让 azure 函数自行重新启动,或者让某些东西通过网络钩子(Hook)或 API 请求或在计时器上运行从外部重新启动 azure 函数

我尝试过使用 Azure API 管理服务,该服务可用于在 azure 中重新启动其他类型的应用程序服务,但事实证明 API 中没有功能来请求重新启动 azure 功能,还研究了 power shell 和这似乎是同样的问题,您可以重新启动不同的应用程序服务,但不能重新启动azure功能

我尝试过使用 API https://learn.microsoft.com/en-us/rest/api/azure/您可以在其中列出 azure 函数中的函数的示例 API 请求获取https://management.azure.com/subscriptions/ {subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/functions?api-version=2016-08-01

但是根据我的研究,没有重新启动 azure 功能的功能

基本上我想重新启动Azure功能,就像我点击这个按钮一样 Azure functions manual stop/start and restart buttons in azure portal

因为有一种情况,由于外部 API,作业每次运行时都会陷入不良状态,我无法控制,手动重新启动会使作业再次运行

最佳答案

重新启动函数的另一种方法是使用 host.json 文件中的“watchDirectories”设置。如果您的 host.json 如下所示:

{
"version": "2.0",
"watchDirectories": [ "Toggle" ]
}

您可以通过在函数中使用以下语句来切换重新启动:

System.IO.File.WriteAllText("D:/home/site/wwwroot/Toggle/restart.conf", DateTime.Now.ToString());     

查看日志,该函数会重新加载,因为它检测到目录中的文件更改:

Watched directory change of type 'Changed' detected for 'D:\home\site\wwwroot\Toggle\restart.conf'  
Host configuration has changed. Signaling restart

关于azure - 有没有办法以编程方式重新启动 azure 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54127675/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com