让一个Blob文件在特定时间触发BlobTrigger Azure函数。

huangapple go评论60阅读模式
英文:

make a blob file trigger a BlobTrigger Azure Function at specific time

问题

使一个 Blob 文件在特定时间触发 BlobTrigger Azure 函数

英文:

I have found that there is BlobTrigger Azure Fucntion, but I don't want a blob file trigger a BlobTrigger Azure Function immediately after blob updated, I hope a blob file can trigger a BlobTrigger Azure Function at specific time. Does BlobTrigger Azure Function support this kindof operation?

make a blob file trigger a BlobTrigger Azure Function at specific time

答案1

得分: 1

Azure Blob Trigger的本质是在轮询所监听的容器/ Blob 存储,当它检测到变化时,会尝试处理该 Blob。您需要重写Blob Storage触发器的基本功能以实现您的目标。

我现在考虑的一个解决方案是使用基于时间的触发器;为此,您需要更新您的 function.json(以下示例每 3 小时触发一次函数):

{
   "bindings": [
      {
         "name": "myTimer",
         "type": "timerTrigger",
         "direction": "in",
         "schedule": "0 */3 * * * *"
      }
   ]
}

您可以在此处查看更多信息:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=python-v1%2Cin-process&pivots=programming-language-python

从文档中摘取的附加示例:

NCRONTAB示例
以下是Azure Functions中定时触发器可以使用的NCRONTAB表达式示例。

示例 触发时机

0 */5 * * * * 每五分钟触发一次
0 0 * * * * 每小时的整点触发一次
0 0 */2 * * * 每两小时触发一次
0 0 9-17 * * * 每天从上午9点到下午5点每小时触发一次
0 30 9 * * * 每天上午9:30触发一次
0 30 9 * * 1-5 每个工作日上午9:30触发一次
0 30 9 * Jan Mon 每个一月份星期一上午9:30触发一次

英文:

The Azure Blob Trigger by essence is polling the container/blob storage it is listening to. So when it detects it, it will try to process that blob. You need to override the basic functionality of the Blob Storage trigger in order to achieve what you want.

One solution I am thinking of now is to use a time-based trigger; for that you need to update your function.json (this example triggers the function every 3 hours):

{
  "bindings": [
    {
      "name": "myTimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 */3 * * * *"
    }
  ]
}

You can check more information here:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=python-v1%2Cin-process&pivots=programming-language-python

Additional examples taken from the docs:

NCRONTAB examples
Here are some examples of NCRONTAB expressions you can use for the timer trigger in Azure Functions.

Example	                When triggered

0 */5 * * * *	        once every five minutes
0 0 * * * *	            once at the top of every hour
0 0 */2 * * *	        once every two hours
0 0 9-17 * * *	        once every hour from 9 AM to 5 PM
0 30 9 * * *	        at 9:30 AM every day
0 30 9 * * 1-5	        at 9:30 AM every weekday
0 30 9 * Jan Mon	    at 9:30 AM every Monday in January

huangapple
  • 本文由 发表于 2023年4月19日 21:45:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76055297.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定