Search code examples
c#azureazure-webjobsazure-webjobssdkazure-webjobs-triggered

.net core azure WebJob 3.0.3 UseTimers missing


I'm attempting to setup a new webjob using .net core 2.1 and I'm running into an issue where UseTimers() appears to be missing when I try to configure the job.

For the life of me I can't seem to find anything that will point me in the right direction as the documentation doesn't appear to be updated to reflect using HostBuilder instead of JobHostConfiguration.

I've even tried looking into the source for the WebJobs extensions but I can't seem to find anything to help and I'm at a loss now.

I've got the following which is fairly boilerplate but this only works when I don't include .UseTimers()

using System.Threading.Tasks; 
using Microsoft.Extensions.Configuration; 
using Microsoft.Extensions.Hosting; 
using Microsoft.Extensions.Logging; 
using Microsoft.Azure.WebJobs; 
using Microsoft.Azure.WebJobs.Extensions;

namespace marqueone.webjob 
{
    class Program
    {
        public static async Task Main(string[] args)
        {

            var builder = new HostBuilder()
            .UseEnvironment("Development")
            .ConfigureWebJobs(b =>
            {
                b.AddAzureStorageCoreServices()
                .AddAzureStorage();
            })
            .ConfigureAppConfiguration(b =>
            {
                b.AddCommandLine(args);
            })
            .ConfigureLogging((context, b) =>
            {
                b.SetMinimumLevel(LogLevel.Debug);
                b.AddConsole();
            })
            //.UseTimers()
            .UseConsoleLifetime();

            var host = builder.Build();
            using (host)
            {
                await host.RunAsync();
            }
        }
    } 
}

Solution

  • As per this link, you should use .AddTimers(), Like the following code:

    .ConfigureWebJobs(config =>
    {
        config.AddAzureStorageCoreServices();
        config.AddTimers();
    })
    

    And also in this link, it explain that:

     in general all the previous config.UseXXX extension methods migrated to 
    
    IHostBuilder builder.AddXXX methods.