Quartz 后台作业管理
建议使用ABP CLI安装包.
在项目的文件夹(.csproj文件)中打开命令行窗口输入以下命令:
添加 NuGet包添加到你的项目:
添加
AbpBackgroundJobsQuartzModule
到你的模块的依赖列表:
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",
};
});
}
你可以选择你喜爱的方式来配置Quaratz.
Quartz默认将作业与调度信息存储在内存中,示例中我们使用选项模式的预配置将其更改为存储到数据库中. 有关Quartz的更多配置请参阅.
当后台作业发生异常时ABP提供了默认异常处理策略,它会为你的作业重试3次,每次间隔3秒. 你可以通过 更改默认重试次数与间隔时间:
[DependsOn(
//...other dependencies
typeof(AbpBackgroundJobsQuartzModule) //Add the new module dependency
)]
public class YourModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpBackgroundJobQuartzOptions>(options =>
{
options.RetryCount = 1;
options.RetryIntervalMillisecond = 1000;
});
}