简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM