【问题标题】:Azure WebJobs Not Finding FunctionsAzure WebJobs 找不到函数
【发布时间】:2019-02-04 22:29:27
【问题描述】:

程序.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();
        }
    }

函数.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}");
    }
}

当我跑步时,我得到:

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

我已经阅读了几个示例,并认为通过创建新的控制台应用程序、引用所需的程序集以及包括上述内容,WebJob 应该“正常工作”。我是否遗漏了一些关键配置?

版本:

【问题讨论】:

  • 你的问题解决了吗?

标签: c# .net azure azure-webjobs


【解决方案1】:

您在配置中缺少 AddTimers(),因为它是一个时间触发函数。

请为您的项目安装包Microsoft.Azure.WebJobs.Extensions,然后在您的program.cs -> Main 方法:将 AddTimers 添加到 webjob 配置中,如下所示:

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

webjob 3.x 的更多配置也可以参考我的previous answer

【讨论】:

    猜你喜欢
    • 2023-04-10
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-09
    • 2016-05-09
    相关资源
    最近更新 更多