我们有一个 Azure WebJob (3.x) 在 Azure 中的 API 应用程序下运行,全部为 Core 2.1。它可以正常发布并运行,但不会显示任何函数或在仪表板上列出函数调用。这很奇怪,因为该作业的控制台输出确实显示它检测到一个函数:
[10/17/2018 09:26:19 > fa7c81: SYS INFO] Run script 'run.cmd' with script host - 'WindowsScriptHost'
[10/17/2018 09:26:19 > fa7c81: SYS INFO] Status changed to Running
[10/17/2018 09:26:19 > fa7c81: INFO]
[10/17/2018 09:26:19 > fa7c81: INFO] D:\local\Temp\jobs\continuous\SubmissionJob\43ucb4rv.ipc>dotnet SubmissionJob.dll
[10/17/2018 09:26:21 > fa7c81: INFO] dbug: Microsoft.Extensions.Hosting.Internal.Host[1]
[10/17/2018 09:26:21 > fa7c81: INFO] Hosting starting
[10/17/2018 09:26:21 > fa7c81: INFO] info: Microsoft.Azure.WebJobs.Hosting.JobHostService[0]
[10/17/2018 09:26:21 > fa7c81: INFO] Starting JobHost
[10/17/2018 09:26:21 > fa7c81: INFO] info: Host.Startup[0]
[10/17/2018 09:26:21 > fa7c81: INFO] Found the following functions:
[10/17/2018 09:26:21 > fa7c81: INFO] SubmissionJob.Functions.ProcessQueueMessageAsync
[10/17/2018 09:26:21 > fa7c81: INFO]
[10/17/2018 09:26:21 > fa7c81: INFO] Application started. Press Ctrl+C to shut down.
[10/17/2018 09:26:21 > fa7c81: INFO] Hosting environment: QA
Program.cs Program
类如下所示:
public static async Task Main(string[] args)
{
var builder = new HostBuilder()
.UseEnvironment(Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"))
.ConfigureWebJobs(b =>
{
b.AddAzureStorageCoreServices()
.AddAzureStorage()
.AddServiceBus()
.AddEventHubs();
})
.ConfigureAppConfiguration(b =>
{
// Adding command line as a configuration source
b.AddCommandLine(args);
})
.ConfigureLogging((context, b) =>
{
b.SetMinimumLevel(LogLevel.Debug);
b.AddConsole();
// If this key exists in any config, use it to enable App Insights
var appInsightsKey = context.Configuration["APPINSIGHTS_INSTRUMENTATIONKEY"];
if (!string.IsNullOrEmpty(appInsightsKey))
{
b.AddApplicationInsights(o => o.InstrumentationKey = appInsightsKey);
}
})
.ConfigureServices((context, services) =>
{
services.AddAutoMapper();
services.AddMemoryCache();
services.AddDbContext<SubmissionsDbContext>(opts =>
opts.UseSqlServer(context.Configuration.GetConnectionString("DefaultConnection")));
// cloud services
services.AddTransient(s =>
CloudStorageAccount.Parse(
context.Configuration.GetConnectionString("AzureQueueConnectionString")));
services.AddTransient<IBlobReadService, AzureBlobReadService>();
services.AddSingleton<IBlobWriteService, AzureBlobWriteService>();
services.AddSingleton<IQueueWriteService, AzureQueueWriteService>();
// submission services
services.AddScoped<ISubmissionStatusService, SubmissionStatusService>();
services.AddSingleton<Functions, Functions>();
// job activator, required in webjobs sdk 3+
services.AddSingleton<IJobActivator>(new WebJobsActivator(services.BuildServiceProvider()));
})
.UseConsoleLifetime();;
var host = builder.Build();
using (host)
{
await host.RunAsync();
}
}
Functions.cs 有一个具有以下签名的方法:
public async Task ProcessQueueMessageAsync([QueueTrigger("operations")] CloudQueueMessage incomingMessage, TextWriter log)
...scm.azurewebsites.net/azurejobs/#/jobs/continuous/SubmissionJob 显示
Continuous WebJob Details SubmissionJob
Running
Run command: run.cmd
但其下方没有函数调用列表,并且作业永久保持在 Running
状态。如果我转到 Kudu 中的“函数”链接,它会显示没有要显示的函数/函数调用。
有什么想法吗?
尽管应用程序构建器明显不同,但其中大部分内容在 Framework 4.7 中运行良好。
最佳答案
这个问题的答案是双重的。
您可以使用
写入 Kudu 仪表板var builder = new HostBuilder()
.ConfigureWebJobs(b =>
{
b.AddDashboardLogging();
});
这将工作并显示 WebJobs 1.x、2.x 的函数调用。但是,从 WebJobs SDK 3.x 开始,此功能已过时。控制台输出将继续显示在 Kudu 仪表板中,但不会检测到并且不会显示函数及其调用。建议改为使用 Application Insights。
var builder = new HostBuilder()
.ConfigureLogging((context, b) =>
{
b.SetMinimumLevel(LogLevel.Debug);
b.AddConsole();
// If this key exists in any config, use it to enable App Insights.
// This may already be configured in Azure Portal if running WebJob udner existing app with App Insights.
var appInsightsKey = context.Configuration["APPINSIGHTS_INSTRUMENTATIONKEY"];
if (!string.IsNullOrEmpty(appInsightsKey))
{
b.AddApplicationInsights(o => o.InstrumentationKey = appInsightsKey);
}
});
确保已使用存储连接字符串配置名为 AzureWebJobsStorage
的连接字符串。
另请参阅:https://github.com/Azure/azure-webjobs-sdk/wiki/Application-Insights-Integration
关于c# - Azure WebJobs (3.x) 连续作业未在仪表板中显示函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52857635/