问题描述
我创建了一个连续的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.ProcessDocumentsRoundAboutAsync'(原因='计时器在 2020-09-09T 09:16:54 .5243173 + 02:00', Id = 9c64dfc4-e7b3-4857-a9bc-df40cc7d58c9)
[09/09/2020 07:16:56> fc5cb9:INFO]已执行 'Functions.ProcessDocumentsRoundAboutAsync'(成功, Id = 9c64dfc4-e7b3-4857-a9bc-df40cc7d58c9)
[09/09/2020 07:22:06> fc5cb9:INFO]执行中 'Functions.ProcessDocumentsRoundAboutAsync'(原因='计时器在 2020-09-09T09:21:54.5364353 + 02:00', id = e06eb211-2a6c-49a0-a9ce-1aee003dc545)
[09/09/2020 07:22:07> fc5cb9:INFO]已执行 'Functions.ProcessDocumentsRoundAboutAsync'(成功, id = e06eb211-2a6c-49a0-a9ce-1aee003dc545)
功能调用日志:
Functions.ProcessDocumentsRoundAboutAsync(09/09/2020 09:21:5 ...) Functions.ProcessDocumentsRoundAboutAsync(09/09/2020 09:20:3 ...) Functions.ProcessDocumentsRoundAboutAsync(09/09/2020 09:16:5 ...)
我找到了this solution,但是它不符合我的需求,因为我想连续运行它(允许我对其进行调试,不需要“热身”),当然我想知道发生这种情况的真正原因。
我不知道为什么到现在为止一切正常,为什么会这样。有任何想法吗?谢谢。