在 Azure Function 中动态设置计划 [英] Dynamically set schedule in Azure Function

查看:19
本文介绍了在 Azure Function 中动态设置计划的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Azure 函数有以下 function.json,其计划设置为每天 9.30 运行.我想要的是动态设置这个 json 的 schedule 属性.当使用我的应用程序的客户端输入日期时,就会出现这种情况,该日期调度程序应该运行.

I have following function.json for my Azure function whose schedule is set to run at 9.30 daily. What I want is to dynamically set the schedule attribute of this json. This scenario arises when a client who is using my application enters date, on that date-scheduler should run.

   {
  "bindings": [
    {
      "name": "myTimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 30 9 * * *" //Want to set dynamically
    }
  ],
  "disabled": false
}

这可能吗?

(另请注意,由于预算原因,我不想使用 Azure Scheduler)

(Also note, I don't want to use Azure Scheduler due to budgeting reasons)

推荐答案

  1. 使用 Kudu API 更改 function.jsonhttps://github.com/projectkudu/kudu/wiki/REST-API

PUT https://{functionAppName}.scm.azurewebsites.net/api/vfs/{pathToFunction.json},标题:如果匹配:*",正文:新的function.json内容

PUT https://{functionAppName}.scm.azurewebsites.net/api/vfs/{pathToFunction.json}, Headers: If-Match: "*", Body: new function.json content

然后发送请求以应用更改

Then send request to apply changes

POST https://{functionAppName}.scm.azurewebsites.net/api/functions/synctriggers

POST https://{functionAppName}.scm.azurewebsites.net/api/functions/synctriggers

或者您可以将队列触发器与initialVisibilityDelay"消息一起使用.在这种情况下,您需要编写自己的代码来实现调度程序.

Or you can use Queue Trigger with "initialVisibilityDelay" messages. In this case you need to write your own code to implement a scheduler.

这篇关于在 Azure Function 中动态设置计划的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆