gpt4 book ai didi

c# - Azure WebJobs 未找到函数

转载 作者:行者123 更新时间:2023-12-03 01:03:57 25 4
gpt4 key购买 nike

程序.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 应该“正常工作”。我是否遗漏了一些关键配置?

版本:

enter image description here

最佳答案

您在配置中缺少 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();

也可以引用我的previous answer有关 webjob 3.x 的更多配置。

关于c# - Azure WebJobs 未找到函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54525272/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com