我的Azure函数有以下function.json,其日程安排设置为每天运行9.30。我想要的是动态设置这个json的schedule
属性。当使用我的应用程序的客户端输入日期时,就会出现这种情况,日期调度程序应该运行。
{
"bindings": [
{
"name": "myTimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 30 9 * * *" //Want to set dynamically
}
],
"disabled": false
}
这可能吗?
(另请注意,由于预算原因,我不想使用Azure Scheduler)
答案 0 :(得分:3)
您可以修改function.json以从应用程序设置中获取cron表达式。
“schedule”:“%TriggerSchedule%”
在appsettings中定义TriggerSchedule。您可以动态修改appsettings,并且函数触发器将与其对齐。
答案 1 :(得分:2)
使用Kudu API更改function.json https://github.com/projectkudu/kudu/wiki/REST-API
PUT https:// {functionAppName} .scm.azurewebsites.net / api / vfs / {pathToFunction.json}, 标题:如果匹配:" *", 正文:新的function.json内容
然后发送申请以应用更改
POST https:// {functionAppName} .scm.azurewebsites.net / api / functions / synctriggers
或者您可以将队列触发器用于" initialVisibilityDelay"消息。在这种情况下,您需要编写自己的代码来实现调度程序。
答案 2 :(得分:0)
这是一个老问题,但仍然相关。我最近遇到了类似的问题。 Azure 函数具有您可以使用的内置功能。它被称为 Durable Functions (Azure Functions) 中的永恒编排。 你可以做类似的事情
[FunctionName("Periodic_Cleanup_Loop")]
public static async Task Run([OrchestrationTrigger] IDurableOrchestrationContext
context)
{
await context.CallActivityAsync("DoCleanup", null);
// sleep for one hour between cleanups
DateTime nextCleanup = context.CurrentUtcDateTime.AddHours(1);
await context.CreateTimer(nextCleanup, CancellationToken.None);
context.ContinueAsNew(null);
}
找到