Quartz 后台作业管理
建议使用ABP CLI安装包.
如果你想手动安装;
添加 NuGet包添加到你的项目:
Quartz是一个可配置的类库,对此ABP框架提供了 AbpQuartzOptions
. 你可以在模块预配置此选项,ABP在初始化Quartz模块时将使用它. 例:
[DependsOn(
//...other dependencies
typeof(AbpBackgroundJobsQuartzModule) //Add the new module dependency
)]
public class YourModule : AbpModule
{
{
var configuration = context.Services.GetConfiguration();
PreConfigure<AbpQuartzOptions>(options =>
{
{
["quartz.jobStore.dataSource"] = "BackgroundJobsDemoApp",
["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz",
["quartz.jobStore.tablePrefix"] = "QRTZ_",
["quartz.serializer.type"] = "json",
["quartz.dataSource.BackgroundJobsDemoApp.connectionString"] = configuration.GetConnectionString("Quartz"),
["quartz.dataSource.BackgroundJobsDemoApp.provider"] = "SqlServer",
["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz",
};
});
}
Quartz默认将作业与调度信息存储在内存中,示例中我们使用选项模式的预配置将其更改为存储到数据库中. 有关Quartz的更多配置请参阅.
你可以通过 AbpBackgroundJobQuartzOptions
选项自定义异常处理策略:
//...other dependencies
typeof(AbpBackgroundJobsQuartzModule) //Add the new module dependency
)]
public class YourModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpBackgroundJobQuartzOptions>(options =>
{
options.RetryStrategy = async (retryIndex, executionContext, exception) =>
{
// customize exception handling
};
});
}