部署连续的 Azure WebJob 和 WebApp 块应用程序
Deploying continuous Azure WebJob and WebApp blocks App
我目前正在通过 Azure DevOps 将一个带有相应 Web 应用程序的 Azure WebJob 部署到 Azure。我的 Web Job 启动主要来自各种示例,例如 https://github.com/Azure/azure-webjobs-sdk/tree/dev/sample/SampleHost
public class Program
{
public static async Task Main()
{
IConfigurationRoot configRoot = null;
var reg = new ServiceRegistry();
reg.Scan(
scanner =>
{
scanner.AssembliesFromApplicationBaseDirectory();
scanner.LookForRegistries();
});
var builder = new HostBuilder()
.ConfigureWebJobs(
f =>
{
f.AddAzureStorageCoreServices();
f.AddTimers();
})
.ConfigureAppConfiguration(
(context, configurationBuilder) =>
{
configurationBuilder.Sources.Clear();
configRoot = configurationBuilder
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", false, true)
.Build();
})
.ConfigureLogging(
(context, b) =>
{
b.AddApplicationInsightsWebJobs(
cfg =>
{
cfg.InstrumentationKey = "xxxx";
});
b.AddConsole();
})
.UseConsoleLifetime();
var host = builder
.UseLamar(reg)
.Build();
using (host)
{
var container = host.Services.GetService<IContainer>();
var section = configRoot.GetSection(AppSettings.SectionKey);
var settings = section.Get<AppSettings>();
container.Configure(
cfg =>
{
cfg.AddSingleton(settings);
});
await host.RunAsync();
}
}
}
据我了解,由于我有第二个文件,其中包含 crontriggers 等功能,因此 webjob 必须 运行 处于连续模式才能保持活动状态。因为我想将 webjob 部署为 web 应用程序的一部分,所以我在发布构建中添加了一个 YAML taks,如下所示:
- task: DotNetCoreCLI@2
displayName: Publish Web Jobs
inputs:
command: publish
publishWebProjects: false
projects: 'Backend/Sources/Application/WebJobs/xxx.WebJobs.csproj'
arguments: '--configuration $(BuildConfiguration) --output $(PublishPath)/App_Data/jobs/continuous/WebJobs /p:DeleteExistingFiles=True'
zipAfterPublish: false
modifyOutputPath: false
该任务的变体取自 https://www.rahulpnath.com/blog/azure-webjobs-dotnet-core-build-depoy/
构建后,我通过任务“Azure App Service deploy”的默认配置一次性部署了 Web 应用程序和作业。
有趣的是:如果我开始使用这个任务和代码,网络应用程序就不会再正确部署了。检查日志,我看到 Web 作业实际上已部署并立即开始工作。因此我认为,Web 作业现在有点阻止 Web 应用程序完全部署,因为它已经 运行ning(并且可能锁定东西?)
我找到的最多的例子是以前版本的网络作业,而且我没有找到任何提到这个问题的例子。有没有可能,这种组合不起作用,我需要单独部署 Web 应用程序和 Web 作业,还是存在其他问题?
Is it possible, this combination doesn't work and I would need to deploy web app and web job seperately, or is there another problem around?
据我所知,您不需要单独部署网络应用和网络作业。
如果我们使用相应的 Web 应用程序部署一个 Azure WebJob,我们需要通过右键单击您的 Web 应用程序并选择来创建 WebJob 项目:
Add / New Azure WebJob project
或者,如果您的解决方案中已有 WebJobs 项目:
Add / Existing WebJob project
另外,webjob关联到web应用,webjob包含在web应用包中,所以你只需要将web应用部署到azure app service.
发布时也会生成webjob的包(有两个zip文件),但你只需要在Azure App Service部署任务中指定web应用包即可。 (选中使用 Web 部署选项发布)
哇,这太棘手了:所以我最终完成了两个单独的部署任务:
对于 WebJobs,我定义了一个虚拟路径:
大多数人写道,webjobs 必须在 wwwroot/App_Data 之下,这是错误的。根据 https://github.com/Azure/app-service-announcements/issues/84,site/jobs/ 也在工作。
首先部署 Web 作业也很重要,否则 Web 应用程序数据会丢失(我不知道为什么)。此外,随着应用程序的部署和启动变得越来越慢,我不得不在 运行 一些 Postman 测试之前插入一个等待任务。
我目前正在通过 Azure DevOps 将一个带有相应 Web 应用程序的 Azure WebJob 部署到 Azure。我的 Web Job 启动主要来自各种示例,例如 https://github.com/Azure/azure-webjobs-sdk/tree/dev/sample/SampleHost
public class Program
{
public static async Task Main()
{
IConfigurationRoot configRoot = null;
var reg = new ServiceRegistry();
reg.Scan(
scanner =>
{
scanner.AssembliesFromApplicationBaseDirectory();
scanner.LookForRegistries();
});
var builder = new HostBuilder()
.ConfigureWebJobs(
f =>
{
f.AddAzureStorageCoreServices();
f.AddTimers();
})
.ConfigureAppConfiguration(
(context, configurationBuilder) =>
{
configurationBuilder.Sources.Clear();
configRoot = configurationBuilder
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", false, true)
.Build();
})
.ConfigureLogging(
(context, b) =>
{
b.AddApplicationInsightsWebJobs(
cfg =>
{
cfg.InstrumentationKey = "xxxx";
});
b.AddConsole();
})
.UseConsoleLifetime();
var host = builder
.UseLamar(reg)
.Build();
using (host)
{
var container = host.Services.GetService<IContainer>();
var section = configRoot.GetSection(AppSettings.SectionKey);
var settings = section.Get<AppSettings>();
container.Configure(
cfg =>
{
cfg.AddSingleton(settings);
});
await host.RunAsync();
}
}
}
据我了解,由于我有第二个文件,其中包含 crontriggers 等功能,因此 webjob 必须 运行 处于连续模式才能保持活动状态。因为我想将 webjob 部署为 web 应用程序的一部分,所以我在发布构建中添加了一个 YAML taks,如下所示:
- task: DotNetCoreCLI@2
displayName: Publish Web Jobs
inputs:
command: publish
publishWebProjects: false
projects: 'Backend/Sources/Application/WebJobs/xxx.WebJobs.csproj'
arguments: '--configuration $(BuildConfiguration) --output $(PublishPath)/App_Data/jobs/continuous/WebJobs /p:DeleteExistingFiles=True'
zipAfterPublish: false
modifyOutputPath: false
该任务的变体取自 https://www.rahulpnath.com/blog/azure-webjobs-dotnet-core-build-depoy/
构建后,我通过任务“Azure App Service deploy”的默认配置一次性部署了 Web 应用程序和作业。
有趣的是:如果我开始使用这个任务和代码,网络应用程序就不会再正确部署了。检查日志,我看到 Web 作业实际上已部署并立即开始工作。因此我认为,Web 作业现在有点阻止 Web 应用程序完全部署,因为它已经 运行ning(并且可能锁定东西?)
我找到的最多的例子是以前版本的网络作业,而且我没有找到任何提到这个问题的例子。有没有可能,这种组合不起作用,我需要单独部署 Web 应用程序和 Web 作业,还是存在其他问题?
Is it possible, this combination doesn't work and I would need to deploy web app and web job seperately, or is there another problem around?
据我所知,您不需要单独部署网络应用和网络作业。
如果我们使用相应的 Web 应用程序部署一个 Azure WebJob,我们需要通过右键单击您的 Web 应用程序并选择来创建 WebJob 项目:
Add / New Azure WebJob project
或者,如果您的解决方案中已有 WebJobs 项目:
Add / Existing WebJob project
另外,webjob关联到web应用,webjob包含在web应用包中,所以你只需要将web应用部署到azure app service.
发布时也会生成webjob的包(有两个zip文件),但你只需要在Azure App Service部署任务中指定web应用包即可。 (选中使用 Web 部署选项发布)
哇,这太棘手了:所以我最终完成了两个单独的部署任务:
对于 WebJobs,我定义了一个虚拟路径:
大多数人写道,webjobs 必须在 wwwroot/App_Data 之下,这是错误的。根据 https://github.com/Azure/app-service-announcements/issues/84,site/jobs/ 也在工作。 首先部署 Web 作业也很重要,否则 Web 应用程序数据会丢失(我不知道为什么)。此外,随着应用程序的部署和启动变得越来越慢,我不得不在 运行 一些 Postman 测试之前插入一个等待任务。