Azure WebJob执行该功能的次数比应执行的次数多

问题描述

我创建了一个连续的WebJob,该WebJob应该每5分钟执行一次我的公共功能。

它已经工作了好几天,但是最近发现它在较短的时间内被两次调用。在开发AppService中,我可以看到它首先被调用,然后分别在1分钟和20秒后被调用两次。在生产中,差异甚至更短(20秒)。

Program.cs:

public static void Main()
{
    var config = new JobHostConfiguration();

    if (config.IsDevelopment)
    {
        config.UseDevelopmentSettings();
    }
    config.UseTimers();

    var host = new JobHost(config);
    // The following code ensures that the WebJob will be running continuously
    host.RunAndBlock();
}

Functions.cs:

public static async Task ProcessDocumentsRoundAboutAsync([TimerTrigger("00:05:00",RunOnStartup = false,UseMonitor = true)] TimerInfo timer)
{
    var handler = new ProcessCandidatesHandler();
    await handler.ExecuteAsync();
}

WebJob输出详细信息表明应该每5分钟调用一次:

[09/09/2020 07:16:54> fc5cb9:INFO]执行中 'Functions.ProcessDocumentsRou​​ndAboutAsync'(原因='计时器在 2020-09-09T 09:16:54 .5243173 + 02:00', Id = 9c64dfc4-e7b3-4857-a9bc-df40cc7d58c9)

[09/09/2020 07:16:56> fc5cb9:INFO]已执行 'Functions.ProcessDocumentsRou​​ndAboutAsync'(成功, Id = 9c64dfc4-e7b3-4857-a9bc-df40cc7d58c9)

[09/09/2020 07:22:06> fc5cb9:INFO]执行中 'Functions.ProcessDocumentsRou​​ndAboutAsync'(原因='计时器在 2020-09-09T09:21:54.5364353 + 02:00', id = e06eb211-2a6c-49a0-a9ce-1aee003dc545)

[09/09/2020 07:22:07> fc5cb9:INFO]已执行 'Functions.ProcessDocumentsRou​​ndAboutAsync'(成功, id = e06eb211-2a6c-49a0-a9ce-1aee003dc545)

功能调用日志:

Functions.ProcessDocumentsRou​​ndAboutAsync(09/09/2020 09:21:5 ...) Functions.ProcessDocumentsRou​​ndAboutAsync(09/09/2020 09:20:3 ...) Functions.ProcessDocumentsRou​​ndAboutAsync(09/09/2020 09:16:5 ...)

我找到了this solution,但是它不符合我的需求,因为我想连续运行它(允许我对其进行调试,不需要“热身”),当然我想知道发生这种情况的真正原因。

我不知道为什么到现在为止一切正常,为什么会这样。有任何想法吗?谢谢。

解决方法

将Web作业配置为连续运行时,它将连续运行而没有任何延迟。 要每五分钟运行一次,请配置一个已触发的预定作业。

enter image description here

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...