Azure WebJobs 找不到函数
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}");
}
}
当我 运行 时,我得到:
dbug: Microsoft.Extensions.Hosting.Internal.Host[1]
Hosting starting
dbug: Microsoft.Extensions.Hosting.Internal.Host[2]
Hosting started
我通读了几个示例,印象中通过创建新的控制台应用程序、引用所需的程序集并包括上述内容,WebJob 应该 "just work"。我是否遗漏了一些关键配置?
版本:
您在配置中缺少 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。
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}");
}
}
当我 运行 时,我得到:
dbug: Microsoft.Extensions.Hosting.Internal.Host[1]
Hosting starting
dbug: Microsoft.Extensions.Hosting.Internal.Host[2]
Hosting started
我通读了几个示例,印象中通过创建新的控制台应用程序、引用所需的程序集并包括上述内容,WebJob 应该 "just work"。我是否遗漏了一些关键配置?
版本:
您在配置中缺少 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();
你也可以参考我的