Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my TimerTrigger'd function in my Azure WebJob app not being detected?

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?

like image 565
Scott Weldon Avatar asked Nov 30 '16 17:11

Scott Weldon


1 Answers

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.

like image 53
Scott Weldon Avatar answered Oct 01 '22 06:10

Scott Weldon