BLAZORLOVER
BLAZORLOVER

Reputation: 2011

Azure WebJobs Not Finding Functions

Program.cs:

    public static void Main(string[] args)
    {
        var builder = new HostBuilder()
            .ConfigureLogging((context, b) =>
            {
                b.SetMinimumLevel(LogLevel.Debug);
                b.AddConsole();
            })
            .UseConsoleLifetime();

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

Functions.cs:

public class Functions
{
    private readonly ISampleServiceA _sampleServiceA;
    private readonly ISampleServiceB _sampleServiceB;

    public Functions(ISampleServiceA sampleServiceA, ISampleServiceB sampleServiceB)
    {
        _sampleServiceA = sampleServiceA;
        _sampleServiceB = sampleServiceB;
    }

    public static void RunSomething([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, ILogger log) // every one minute
    {
        if (myTimer.IsPastDue)
        {
            log.LogInformation("Timer is running late!");
        }
        log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
    }
}

When I run, I get:

dbug: Microsoft.Extensions.Hosting.Internal.Host[1]
      Hosting starting
dbug: Microsoft.Extensions.Hosting.Internal.Host[2]
      Hosting started

I've read through several examples and am under the impression that by creating a new console app, referencing required assemblies, and including the above, the WebJob should "just work". Have I omitted some crucial configuration?

Versions:

enter image description here

Upvotes: 1

Views: 1733

Answers (1)

Ivan Glasenberg
Ivan Glasenberg

Reputation: 29940

You're missing AddTimers() in the configuration since it's a time trigger function.

Please install the package Microsoft.Azure.WebJobs.Extensions for you project, then in your program.cs -> Main method: add AddTimers to the webjob configuration, like below:

                var builder = new HostBuilder()
                .ConfigureWebJobs(
                b =>
                {
                    b.AddTimers();
                    //other configure
                })
                .ConfigureLogging((context, b) =>
                {
                    b.SetMinimumLevel(LogLevel.Debug);
                    b.AddConsole();
                })
                // your other configure
                .UseConsoleLifetime();

You can also refer to my previous answer for more configuration for webjob 3.x.

Upvotes: 3

Related Questions