I created a continous WebJob which is supposed to execute my public function every 5 minutes.
It has been working fine for some days but recently noticed it's being called twice in a shorter period of time. In development AppService I can see it gets called firstly and twice 1 minute and 20 seconds later. In production the difference is even shorter (20 seconds).
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();
}
The WebJob output details says it's supposed to be calling it every 5 minutes:
[09/09/2020 07:16:54 > fc5cb9: INFO] Executing 'Functions.ProcessDocumentsRoundAboutAsync' (Reason='Timer fired at 2020-09-09T09:16:54.5243173+02:00', Id=9c64dfc4-e7b3-4857-a9bc-df40cc7d58c9)
[09/09/2020 07:16:56 > fc5cb9: INFO] Executed 'Functions.ProcessDocumentsRoundAboutAsync' (Succeeded, Id=9c64dfc4-e7b3-4857-a9bc-df40cc7d58c9)
[09/09/2020 07:22:06 > fc5cb9: INFO] Executing 'Functions.ProcessDocumentsRoundAboutAsync' (Reason='Timer fired at 2020-09-09T09:21:54.5364353+02:00', Id=e06eb211-2a6c-49a0-a9ce-1aee003dc545)
[09/09/2020 07:22:07 > fc5cb9: INFO] Executed 'Functions.ProcessDocumentsRoundAboutAsync' (Succeeded, Id=e06eb211-2a6c-49a0-a9ce-1aee003dc545)
Functions invokation log:
Functions.ProcessDocumentsRoundAboutAsync (09/09/2020 09:21:5 ...) Functions.ProcessDocumentsRoundAboutAsync (09/09/2020 09:20:3 ...) Functions.ProcessDocumentsRoundAboutAsync (09/09/2020 09:16:5 ...)
I found this solution but it doesn't fit my needs since I want to run it continuously (allows me to debug it, it doesn't need to "warm up") and of course I want to know the real reason why is this supposed to be happening.
I don't get why has this been working fine until now and why is this happening. Any ideas? Thanks.
When you configure a web job to run continuously, it runs continuously without any delay. To run it every five minutes, configure a Triggered scheduled job.