简体   繁体   English

Azure Blob 存储触发器函数未触发

[英]Azure Blob Storage trigger Function not firing

When creating an Azure Function blob trigger template that uses an App Service plan for hosting, the function triggers correctly when configured as "Always on".创建使用应用服务计划进行托管的 Azure 函数 blob 触发器模板时,该函数在配置为“始终开启”时正确触发。 I have tested by running the app in the Azure console, and by adding a file though the Microsoft Azure Storage Explorer.我通过在 Azure 控制台中运行应用程序并通过 Microsoft Azure 存储资源管理器添加文件进行了测试。 The logs of these triggers can be found when viewing the Monitor screen for the function.在查看函数的Monitor屏幕时可以找到这些触发器的日志。

When creating the same function using the Blob Storage template but this time choosing "Consumption" instead of App Service plan, nothing is displaying under monitor.使用 Blob 存储模板创建相同的函数但这次选择“消耗”而不是应用服务计划时,监视器下没有显示任何内容。 When I run a test in the Azure console or add a file to the target Blob container, these trigger logs do not display on the monitor screen.当我在 Azure 控制台中运行测试或将文件添加到目标 Blob 容器时,这些触发器日志不会显示在monitor屏幕上。

What can be done to ensure that this trigger template is firing when a new file is added to the Blob container?当将新文件添加到 Blob 容器时,如何确保触发此触发器模板?

You can run Azure Functions in two different modes: Consumption plan and App Service plan.可以在两种不同的模式下运行 Azure Functions:消耗计划和应用服务计划。 You must choose the type of hosting plan during the creation of the function app.您必须在创建函数应用期间选择托管计划的类型。 You can't change it afterward.之后你不能改变它。

Consumption Plan消费计划

The consumption plan automatically allocates compute power when your code is running, scales out as necessary to handle load, and then scales down when code is not running.消耗计划会在您的代码运行时自动分配计算能力,根据需要扩展以处理负载,然后在代码未运行时缩减。 You don't have to pay for idle VMs and don't have to reserve capacity in advance.您无需为空闲 VM 付费,也无需提前预留容量。 This is the serverless app model.这是无服务器应用程序模型。 The magic behind a consumption plan is all done via the scale controller.消费计划背后的魔法都是通过规模控制器完成的。 The scale controller automatically scales CPU and memory resources by adding additional function app instances.缩放控制器通过添加额外的函数应用实例来自动缩放 CPU 和内存资源。 Scaling is based on the number of events that its functions are triggered on.缩放基于触发其功能的事件数量。

App Service Plan应用服务计划

In the App Service plan, your function apps run on dedicated VMs on Basic, Standard, Premium, and Isolated SKUs.在应用服务计划中,你的函数应用在基本、标准、高级和独立 SKU 上的专用 VM 上运行。 You can scale up by choosing a different App Service plan, but the function app is always running.您可以通过选择不同的应用服务计划来扩展,但函数应用始终在运行。 Scaling is done manually or you can enable autoscale.缩放是手动完成的,或者您可以启用自动缩放。

Because of the difference in nature, App service plans are always available if enabled so it triggered almost immediately.由于性质不同,应用服务计划在启用后始终可用,因此它几乎立即触发。 And in Consumption based plan it goes in a idle mode if it is not being used.在基于消耗的计划中,如果不使用它,它会进入空闲模式。

Additional reference:补充参考:

https://stackoverflow.com/a/54094025/6049604 https://stackoverflow.com/a/54094025/6049604

Hope it helps.希望能帮助到你。

The explanation provided by Mohit is right, but I want to add some information about it after my testing. Mohit提供的解释是对的,但我想在我测试后添加一些关于它的信息。

I test it in my side again, when I test it first time, the function was triggered successfully by the blob storage.我在我身边再次测试,第一次测试时,该功能被blob存储成功触发。 Second time, I left the function there for a moment and then upload a file to blob storage.第二次,我将函数留在那里片刻,然后将文件上传到 Blob 存储。 It was almost 13 minutes before I saw the log in "Monitor" screen.大约 13 分钟后,我才看到登录“监控”屏幕。

I think there are two reasons to cause it, one is mentioned by Mohit, the consumption plan will lead to the function idle for a few moment.我觉得有两个原因,一个是Mohit提到的,消费计划会导致功能闲置一会儿。 As far as I know, if we leave the function there for about 20 minutes , it will fall asleep(not hot start).据我所知,如果我们将函数留在那里大约 20 分钟,它会进入睡眠状态(不是热启动)。 So when the file was uploaded to blob storage, it needs a few minutes to start.因此,当文件上传到 blob 存储时,它需要几分钟才能启动。 And then the "Monitor" also needs about 5 minutes to show the log in screen.然后“监视器”也需要大约 5 分钟才能显示登录屏幕。

Because of the two reasons above, I wait about 13 minutes to see the log in "Monitor".由于上述两个原因,我等待了大约13分钟才能看到“监视器”中的日志。 So maybe you didn't see the log because it appears too later.所以也许你没有看到日志,因为它出现得太晚了。 For this problem, I think you can choose an app service plan if you don't care about the cost or choose a consumption plan it you don't care the waiting time.(or choose an app service plan which is F1: Free).对于这个问题,我觉得你可以选择不在乎费用的app服务计划或者不在乎等待时间的消费计划。(或者选择F1:免费的app服务计划) .

Hope it would be helpful to your problem~希望对你的问题有所帮助~

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM