Azure功能:计时器触发器和消耗计划问题 [英] Azure Functions: timer trigger and consumption plan issue

查看:133
本文介绍了Azure功能:计时器触发器和消耗计划问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的开发环境中,我有一个具有21个功能的Azure函数,并且应用程序计划是使用计划.

In my dev environment, I have an Azure Functions with 21 functions and the app plan is consumption.

某些功能具有计时器触发器,并且在过程结束时,每个功能都会发送一封电子邮件.我有2种类型的计时器触发器:

Some functions have a timer trigger and at the end of the process each function sends an email. I have 2 type of timer trigger:

  • 每20分钟运行一次功能
  • 在晚上的特定时间运行一次功能

该功能每20分钟执行一次我期望的工作.很好.

Every 20 minutes the function is doing what I expect. Great.

我要面对的问题是必须在特定时间启动的功能.基本上,直到我打开门户并在Azure功能上执行某些操作(例如,打开其中一个的监视器)后,它们才会启动.

The problem I'm facing is with the function that they have to start at a particular time. Basically, they don't start until I open the portal and do something on the Azure Function (for example open the monitor for one of them).

从代码的角度来看,具有计时器触发器的所有功能的定义如下:

In the code point of view, all functions with the timer trigger are defined like that:

[FunctionName("invoiceMonthlyGeneratorTimer")]
public void Run([TimerTrigger("%Timers:GenerateMonthlyInvoices%")] TimerInfo myTimer)
{
    // ..
}

[FunctionName("invoiceDunningTimer")]
public async Task Run([TimerTrigger("%Timers:DunningTimer%")] TimerInfo timer)
{
    // ...
}

计时器的配置位于设置文件中,例如:

The configuration of the timer is in the settings file like:

"Timers": {
    "DunningTimer": "0 0 4 * * *",
    "GenerateMonthlyInvoices": "0 0 4 * * *"
}

通常来说,这种方法在开发环境中有效,并且在生产环境中完美运行.

Generally, speaking, this approach was working in dev environment and it is working perfectly in the production environment.

因为每个功能都会发送一封电子邮件,所以我希望每天早晨都能在收件箱中找到一些电子邮件,但不会发生.然后,我打开Azure门户以查看日志和监视器.

Because each function sends an email, I expect each morning to find in my inbox some emails but it doesn't happen. Then, I open the Azure portal to see the logs and the monitor.

在门户中打开Azure功能.

Open the Azure function in the portal.

打开显示器的功能

鲸鱼,几秒钟后,我开始收到所有服务的电子邮件!在生产环境中,我没有开发人员拥有的所有功能,因为我想在部署之前进行测试.在生产过程中,这些功能可以正常运行,并在正确的时间启动.

Whala, after a couple of seconds, I start to receive the email for all services! In the production environment I don't have all the function I have in dev because I want to test before deploying. In prod the functions are working fine and start at the right time.

如果我查看Application Insights,则只能找到打开监视器时的日志.

If I look at Application Insights, I can find only the logs for the time I opened the monitor.

日志中有一件有趣的事情:

There is one interesting thing in the log:

触发器详细信息:UnscheduledInvocation原因:IsPastDue,原始时间表:2020-07-24T05:00:00.0000000 + 00:00

Trigger Details: UnscheduledInvocationReason: IsPastDue, OriginalSchedule: 2020-07-24T05:00:00.0000000+00:00

显然,在同一Azure函数中,您不能有多个计时器触发器.我在 Github 上打开了一个问题,因此如果其他开发人员也面临同样的问题.与HTTP触发器类似的内容,请参见 post .

Apparently, you can't have more than a couple of timer triggers in the same Azure Functions. I opened an issue on Github, so if other devs are facing the same. Something similar with HTTP triggers, look this post.

推荐答案

您的函数应用程序中函数过多,它们可能会相互影响.我遇到了类似的问题,在这种情况下,计时器触发功能在一个功能应用程序中不起作用.但是,当我将它们部署到不同功能的应用程序时,它们可以正常工作.因此您可以尝试将第二个功能部署到另一个功能应用程序.

There are too many functions in your function app, they may interact each other. I met similar problem with this, in that case, the timer trigger functions in one function app and did not work. But when i deploy them to different function apps, they work fine. so you can try to deploy your second function to another function app.

我建议您向Microsoft报告此问题,他们可以了解有关此问题的更多信息,并且可能有更好的解决方案.

And I suggest you report this problem to Microsoft, they can know more information about this problem, and may have a better solution.

这篇关于Azure功能:计时器触发器和消耗计划问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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