I have an Azure WebJob console app that won't recognize the TimerTrigger
that I have set up.
I have the default Program.cs
generated by Visual Studio:
class Program
{
static void Main()
{
var config = new JobHostConfiguration();
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
var host = new JobHost();
host.RunAndBlock();
}
}
I added my new function to Functions.cs
:
public static void MyFunction([TimerTrigger("0 */2 * * * *",
RunOnStartup = true)]
TimerInfo timerInfo,
TextWriter log)
{
log.WriteLine("MyFunction started!");
}
(I installed the WebJobs.Extensions
NuGet package, so my code compiles fine.)
I also added this line:
config.UseTimers();
to the Main
function as mentioned in this answer, but for some reason, my new function still isn't triggered.
When I start the app, I see this output:
Found the following functions:
MyNamespace.Functions.ProcessQueueMessage
Job host started
So it doesn't see my new function.
Why is this happening, and how can I fix it?
After comparing the contents of my Program.cs
to what others had posted online (including the TimerTrigger docs), I found a small difference.
In the Main
function, I changed:
var host = new JobHost();
to:
var host = new JobHost(config);
and it worked. I know for sure that I didn't change that before, so apparently this was a bug in the Azure WebJob template.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With