Kar*_*sai 5 json azure azure-functions
我的Azure函数具有以下function.json,其日程表设置为每天9.30运行。我想要的是动态设置schedule此json 的属性。当使用我的应用程序的客户端输入日期时,就会出现这种情况,该日期计划程序应该在该日期表上运行。
{
"bindings": [
{
"name": "myTimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 30 9 * * *" //Want to set dynamically
}
],
"disabled": false
}
Run Code Online (Sandbox Code Playgroud)
这可能吗?
(还请注意,由于预算原因,我不想使用Azure Scheduler)
您可以修改您的 function.json 以从应用程序设置中获取 cron 表达式。
"schedule": "%TriggerSchedule%"
在您的应用设置中定义 TriggerSchedule。您可以动态修改您的 appsettings,并且函数触发器将与其对齐。
使用 Kudu API 更改 function.json https://github.com/projectkudu/kudu/wiki/REST-API
PUT https://{functionAppName}.scm.azurewebsites.net/api/vfs/{pathToFunction.json},标头:If-Match:“*”,正文:新的 function.json 内容
然后发送请求以应用更改
POST https://{functionAppName}.scm.azurewebsites.net/api/functions/synctriggers
或者您可以将队列触发器与“initialVisibilityDelay”消息一起使用。在这种情况下,您需要编写自己的代码来实现调度程序。
小智 5
这是一个老问题,但仍然相关。我最近遇到了类似的问题。Azure 函数具有可供您使用的内置功能。它被称为持久函数(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);
}
Run Code Online (Sandbox Code Playgroud)
更多信息可以在https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-eternal-orchestrations?tabs=csharp找到
| 归档时间: |
|
| 查看次数: |
1613 次 |
| 最近记录: |