为从 Visual Studio 发布的 Azure 函数更改 Azure 中的计时器间隔
Change timer interval in Azure for Azure Function published from Visual Studio
我有一个函数应用,代码如下
public static void Run([TimerTrigger("*/5 * * * * *")]TimerInfo myTimer, TraceWriter log)
这每 5 秒执行一次我的函数。在生产中,我希望间隔为 30 秒。在我将函数发布到 Azure 后,它可以工作并且每 5 秒 运行。
在功能设置中集成页面的顶部有一条消息"Your app is currently in read-only mode because you have published a generated function.json. Changes made to function.json will not be honored by the Functions runtime"并且该页面是灰色的。
那么我如何在开发和生产中为我的定时器功能设置不同的时间表?
使您的日程安排可配置。在代码中这样声明:
[TimerTrigger("%schedule%")]
然后添加名为 schedule
且值为 */5 * * * * *
的开发设置和值为 */30 * * * * *
.
的生产设置
这应该总结此处给出的其他答案:
配置本地设置
- 向您的项目添加一个 local.settings.json 文件。
- 插入以下代码:
{
"Values": {
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=XXXXXXXXXX;AccountKey=XXXXXXXXXX",
"AzureWebJobsDashboard": "DefaultEndpointsProtocol=https;AccountName=XXXXXXXXXX;AccountKey=XXXXXXXXXX",
"schedule": "*/5 * * * * *",
"//": "put additional settings in here"
},
"Host": {
"LocalHttpPort": 7071,
"CORS": "*"
},
"ConnectionStrings": {
"SQLConnectionString": "XXXXXXXXXX"
}
}
- 像
一样设置触发器属性
[TimerTrigger("%schedule%")]
配置 Azure
- 转到 Azure Portal 并转到功能,单击您的功能,然后 select
Application settings
- 在应用程序设置中select
Add new setting
- 输入
schedule
作为键,输入 */30 * * * * *
作为值
- 点击左上角的
save
- 重新部署您的函数
我有一个函数应用,代码如下
public static void Run([TimerTrigger("*/5 * * * * *")]TimerInfo myTimer, TraceWriter log)
这每 5 秒执行一次我的函数。在生产中,我希望间隔为 30 秒。在我将函数发布到 Azure 后,它可以工作并且每 5 秒 运行。
在功能设置中集成页面的顶部有一条消息"Your app is currently in read-only mode because you have published a generated function.json. Changes made to function.json will not be honored by the Functions runtime"并且该页面是灰色的。
那么我如何在开发和生产中为我的定时器功能设置不同的时间表?
使您的日程安排可配置。在代码中这样声明:
[TimerTrigger("%schedule%")]
然后添加名为 schedule
且值为 */5 * * * * *
的开发设置和值为 */30 * * * * *
.
这应该总结此处给出的其他答案:
配置本地设置
- 向您的项目添加一个 local.settings.json 文件。
- 插入以下代码:
{
"Values": {
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=XXXXXXXXXX;AccountKey=XXXXXXXXXX",
"AzureWebJobsDashboard": "DefaultEndpointsProtocol=https;AccountName=XXXXXXXXXX;AccountKey=XXXXXXXXXX",
"schedule": "*/5 * * * * *",
"//": "put additional settings in here"
},
"Host": {
"LocalHttpPort": 7071,
"CORS": "*"
},
"ConnectionStrings": {
"SQLConnectionString": "XXXXXXXXXX"
}
}
- 像 一样设置触发器属性
[TimerTrigger("%schedule%")]
配置 Azure
- 转到 Azure Portal 并转到功能,单击您的功能,然后 select
Application settings
- 在应用程序设置中select
Add new setting
- 输入
schedule
作为键,输入*/30 * * * * *
作为值 - 点击左上角的
save
- 重新部署您的函数