mirror of https://github.com/abpframework/abp.git
11 changed files with 333 additions and 8 deletions
@ -0,0 +1,73 @@ |
|||||
|
# Quartz Background Job Manager |
||||
|
|
||||
|
[Quartz](https://www.quartz-scheduler.net/) is an advanced background job manager. You can integrate Quartz with the ABP Framework to use it instead of the [default background job manager](Background-Jobs.md). In this way, you can use the same background job API for Quartz and your code will be independent of Quartz. If you like, you can directly use Quartz's API, too. |
||||
|
|
||||
|
> See the [background jobs document](Background-Jobs.md) to learn how to use the background job system. This document only shows how to install and configure the Quartz integration. |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
It is suggested to use the [ABP CLI](CLI.md) to install this package. |
||||
|
|
||||
|
### Using the ABP CLI |
||||
|
|
||||
|
Open a command line window in the folder of the project (.csproj file) and type the following command: |
||||
|
|
||||
|
````bash |
||||
|
abp add-package Volo.Abp.BackgroundJobs.Quartz |
||||
|
```` |
||||
|
|
||||
|
### Manual Installation |
||||
|
|
||||
|
If you want to manually install; |
||||
|
|
||||
|
1. Add the [Volo.Abp.BackgroundJobs.Quartz](https://www.nuget.org/packages/Volo.Abp.BackgroundJobs.Quartz) NuGet package to your project: |
||||
|
|
||||
|
```` |
||||
|
Install-Package Volo.Abp.BackgroundJobs.Quartz |
||||
|
```` |
||||
|
|
||||
|
2. Add the `AbpBackgroundJobsQuartzModule` to the dependency list of your module: |
||||
|
|
||||
|
````csharp |
||||
|
[DependsOn( |
||||
|
//...other dependencies |
||||
|
typeof(AbpBackgroundJobsQuartzModule) //Add the new module dependency |
||||
|
)] |
||||
|
public class YourModule : AbpModule |
||||
|
{ |
||||
|
} |
||||
|
```` |
||||
|
|
||||
|
## Configuration |
||||
|
|
||||
|
Quartz is a very configurable library,and the ABP framework provides `AbpQuartzPreOptions` for this. You can use the `PreConfigure` method in your module class to pre-configure this option. ABP will use it when initializing the Quartz module. For example: |
||||
|
|
||||
|
````csharp |
||||
|
[DependsOn( |
||||
|
//...other dependencies |
||||
|
typeof(AbpBackgroundJobsQuartzModule) //Add the new module dependency |
||||
|
)] |
||||
|
public class YourModule : AbpModule |
||||
|
{ |
||||
|
public override void PreConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
var configuration = context.Services.GetConfiguration(); |
||||
|
|
||||
|
PreConfigure<AbpQuartzPreOptions>(options => |
||||
|
{ |
||||
|
options.Properties = new NameValueCollection |
||||
|
{ |
||||
|
["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 stores job and scheduling information **in memory by default**. In the example, we use the pre-configuration of [options pattern](Options.md) to change it to the database. For more configuration of Quartz, please refer to the Quartz's [documentation](https://www.quartz-scheduler.net/documentation/quartz-3.x/tutorial/index.html). |
||||
@ -0,0 +1,3 @@ |
|||||
|
# Background Workers |
||||
|
|
||||
|
TODO |
||||
@ -0,0 +1,68 @@ |
|||||
|
# Quartz Background Worker Manager |
||||
|
|
||||
|
[Quartz](https://www.quartz-scheduler.net/) is an advanced background worker manager. You can integrate Quartz with the ABP Framework to use it instead of the [default background worker manager](Background-Worker.md). ABP simply integrates quartz. |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
It is suggested to use the [ABP CLI](CLI.md) to install this package. |
||||
|
|
||||
|
### Using the ABP CLI |
||||
|
|
||||
|
Open a command line window in the folder of the project (.csproj file) and type the following command: |
||||
|
|
||||
|
````bash |
||||
|
abp add-package Volo.Abp.BackgroundWorkers.Quartz |
||||
|
```` |
||||
|
|
||||
|
### Manual Installation |
||||
|
|
||||
|
If you want to manually install; |
||||
|
|
||||
|
1. Add the [Volo.Abp.BackgroundWorkers.Quartz](https://www.nuget.org/packages/Volo.Abp.BackgroundWorkers.Quartz) NuGet package to your project: |
||||
|
|
||||
|
```` |
||||
|
Install-Package Volo.Abp.BackgroundWorkers.Quartz |
||||
|
```` |
||||
|
|
||||
|
2. Add the `AbpBackgroundWorkersQuartzModule` to the dependency list of your module: |
||||
|
|
||||
|
````csharp |
||||
|
[DependsOn( |
||||
|
//...other dependencies |
||||
|
typeof(AbpBackgroundWorkersQuartzModule) //Add the new module dependency |
||||
|
)] |
||||
|
public class YourModule : AbpModule |
||||
|
{ |
||||
|
} |
||||
|
```` |
||||
|
|
||||
|
### Configuration |
||||
|
|
||||
|
See [Configuration](Background-Jobs-Quartz.md#Configuration). |
||||
|
|
||||
|
### Create a Background Worker |
||||
|
|
||||
|
A background work is a class that derives from the `QuartzBackgroundWorkerBase` base class. for example. A simple worker class is shown below: |
||||
|
|
||||
|
```` csharp |
||||
|
public class MyLogWorker : QuartzBackgroundWorkerBase |
||||
|
{ |
||||
|
public MyLogWorker() |
||||
|
{ |
||||
|
JobDetail = JobBuilder.Create<MyLogWorker>().Build(); |
||||
|
Trigger = TriggerBuilder.Create().StartNow().Build(); |
||||
|
} |
||||
|
|
||||
|
public override Task Execute(IJobExecutionContext context) |
||||
|
{ |
||||
|
Logger.LogInformation("Executed MyLogWorker..!"); |
||||
|
return Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
|
```` |
||||
|
|
||||
|
We simply implemented the Execute method to write a log. The background worker is a **singleton by default**. If you want, you can also implement a [dependency interface](Dependency-Injection.md#DependencyInterfaces) to register it as another life cycle. |
||||
|
|
||||
|
### More |
||||
|
|
||||
|
Please see Quartz's [documentation](https://www.quartz-scheduler.net/documentation/index.html) for more information. |
||||
@ -0,0 +1,73 @@ |
|||||
|
# Quartz 后台作业管理 |
||||
|
|
||||
|
[Quartz](https://www.quartz-scheduler.net/)是一个高级的作业管理. 你可以用ABP框架集成Quartz代替[默认后台作业管理](Background-Jobs.md). 通过这种方式你可以使用相同的后台作业API,将你的代码独立于Quartz. 如果你喜欢也可以直接使用Quartz的API. |
||||
|
|
||||
|
> 参阅[后台作业文档](Background-Jobs.md),学习如何使用后台作业系统. 本文只介绍了如何安装和配置Quartz集成. |
||||
|
|
||||
|
## 安装 |
||||
|
|
||||
|
建议使用[ABP CLI](CLI.md)安装包. |
||||
|
|
||||
|
### 使用ABP CLI |
||||
|
|
||||
|
在项目的文件夹(.csproj文件)中打开命令行窗口输入以下命令: |
||||
|
|
||||
|
````bash |
||||
|
abp add-package Volo.Abp.BackgroundJobs.Quartz |
||||
|
```` |
||||
|
|
||||
|
### 手动安装 |
||||
|
|
||||
|
如果你想手动安装; |
||||
|
|
||||
|
1. 添加 [Volo.Abp.BackgroundJobs.Quartz](https://www.nuget.org/packages/Volo.Abp.BackgroundJobs.Quartz) NuGet包添加到你的项目: |
||||
|
|
||||
|
```` |
||||
|
Install-Package Volo.Abp.BackgroundJobs.Quartz |
||||
|
```` |
||||
|
|
||||
|
2. 添加 `AbpBackgroundJobsQuartzModule` 到你的模块的依赖列表: |
||||
|
|
||||
|
````csharp |
||||
|
[DependsOn( |
||||
|
//...other dependencies |
||||
|
typeof(AbpBackgroundJobsQuartzModule) //Add the new module dependency |
||||
|
)] |
||||
|
public class YourModule : AbpModule |
||||
|
{ |
||||
|
} |
||||
|
```` |
||||
|
|
||||
|
## 配置 |
||||
|
|
||||
|
Quartz是一个可配置的类库,对此ABP框架提供了 `AbpQuartzPreOptions`. 你可以在模块预配置此选项,ABP在初始化Quartz模块时将使用它. 例: |
||||
|
|
||||
|
````csharp |
||||
|
[DependsOn( |
||||
|
//...other dependencies |
||||
|
typeof(AbpBackgroundJobsQuartzModule) //Add the new module dependency |
||||
|
)] |
||||
|
public class YourModule : AbpModule |
||||
|
{ |
||||
|
public override void PreConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
var configuration = context.Services.GetConfiguration(); |
||||
|
|
||||
|
PreConfigure<AbpQuartzPreOptions>(options => |
||||
|
{ |
||||
|
options.Properties = new NameValueCollection |
||||
|
{ |
||||
|
["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**默认**将作业与调度信息存储在**内存**中,示例中我们使用[选项模式](Options.md)的预配置将其更改为存储到数据库中. 有关Quartz的更多配置请参阅[Quartz文档](https://www.quartz-scheduler.net/documentation/quartz-3.x/tutorial/index.html). |
||||
@ -0,0 +1,68 @@ |
|||||
|
# Quartz 后台工作者管理 |
||||
|
|
||||
|
[Quartz](https://www.quartz-scheduler.net/)是一个高级的后台工作者管理. 你可以用ABP框架集成Quartz代替[默认后台工作者管理](Background-Workers.md). ABP简单的集成了Quartz. |
||||
|
|
||||
|
## 安装 |
||||
|
|
||||
|
建议使用[ABP CLI](CLI.md)安装包. |
||||
|
|
||||
|
### 使用ABP CLI |
||||
|
|
||||
|
在项目的文件夹(.csproj文件)中打开命令行窗口输入以下命令: |
||||
|
|
||||
|
````bash |
||||
|
abp add-package Volo.Abp.BackgroundWorkers.Quartz |
||||
|
```` |
||||
|
|
||||
|
### 手动安装 |
||||
|
|
||||
|
如果你想手动安装; |
||||
|
|
||||
|
1. 添加 [Volo.Abp.BackgroundWorkers.Quartz](https://www.nuget.org/packages/Volo.Abp.BackgroundWorkers.Quartz) NuGet包添加到你的项目: |
||||
|
|
||||
|
```` |
||||
|
Install-Package Volo.Abp.BackgroundWorkers.Quartz |
||||
|
```` |
||||
|
|
||||
|
2. 添加 `AbpBackgroundWorkersQuartzModule` 到你的模块的依赖列表: |
||||
|
|
||||
|
````csharp |
||||
|
[DependsOn( |
||||
|
//...other dependencies |
||||
|
typeof(AbpBackgroundWorkersQuartzModule) //Add the new module dependency |
||||
|
)] |
||||
|
public class YourModule : AbpModule |
||||
|
{ |
||||
|
} |
||||
|
```` |
||||
|
|
||||
|
### 配置 |
||||
|
|
||||
|
参阅[配置](Background-Jobs-Quartz.md#配置). |
||||
|
|
||||
|
### 创建后台工作者 |
||||
|
|
||||
|
后台工作者是一个继承自 `QuartzBackgroundWorkerBase` 基类的类. 一个简单的工作者如下所示: |
||||
|
|
||||
|
```` csharp |
||||
|
public class MyLogWorker : QuartzBackgroundWorkerBase |
||||
|
{ |
||||
|
public MyLogWorker() |
||||
|
{ |
||||
|
JobDetail = JobBuilder.Create<MyLogWorker>().Build(); |
||||
|
Trigger = TriggerBuilder.Create().StartNow().Build(); |
||||
|
} |
||||
|
|
||||
|
public override Task Execute(IJobExecutionContext context) |
||||
|
{ |
||||
|
Logger.LogInformation("Executed MyLogWorker..!"); |
||||
|
return Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
|
```` |
||||
|
|
||||
|
示例中我们重写了 `Execute` 方法写入日志. 后台工作者默认是**单例**. 如果你需要,也可以实现[依赖接口](Dependency-Injection.md#依赖接口)将其注册为其他的生命周期. |
||||
|
|
||||
|
### 更多 |
||||
|
|
||||
|
参阅Quartz[文档](https://www.quartz-scheduler.net/documentation/index.html)了解更多信息. |
||||
@ -0,0 +1,3 @@ |
|||||
|
# 后台工作者 |
||||
|
|
||||
|
TODO |
||||
Loading…
Reference in new issue