【发布时间】:2021-05-13 12:58:21
【问题描述】:
如何处理在 ASP.NET Core 中创建并托管在 Azure App Service 中且横向扩展至多个实例的 API 的 Quartz 配置?
API 当前始终托管在单个 IIS 应用程序中,因此 Quartz 配置如下所示,未使用集群配置
private static NameValueCollection SchedulerConfiguration(IConfiguration configuration)
{
var schedulerConfiguration = new NameValueCollection();
schedulerConfiguration["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
schedulerConfiguration["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz";
schedulerConfiguration["quartz.jobStore.tablePrefix"] = "QRTZ_";
schedulerConfiguration["quartz.jobStore.dataSource"] = "default";
schedulerConfiguration["quartz.dataSource.default.connectionString"] = configuration["ConnectionString"];
schedulerConfiguration["quartz.dataSource.default.provider"] = "SqlServer";
schedulerConfiguration["quartz.serializer.type"] = "json";
return schedulerConfiguration;
}
它利用QuartzHostedService 处理预定的后台作业
services.AddHostedService<QuartzHostedService>();
我做了一个小实验,并将 API 部署到 Azure 应用服务实例中,然后在 API 中创建了一个 Quartz 作业,并在触发器触发之前将实例数量扩展到 4 个。 我的假设是,不做任何更改上述配置作业将被执行 4 次,因为当新的 3 个实例启动时,它们都会从数据库中读取作业详细信息并注册触发器以在特定时间触发。但令我惊讶的是,这项工作只执行了一次。
- 知道为什么作业只执行一次吗?
- 在横向扩展的 Azure 应用服务中托管 Quartz 调度程序时是否应该利用集群配置?
【问题讨论】:
标签: asp.net-core azure-web-app-service quartz.net