You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.1 KiB
82 lines
2.1 KiB
2 weeks ago
|
# 定时任务Job
|
||
|
用来执行一些定时任务,依赖Quartz,如果job同步执行请加 [DisallowConcurrentExecution] 特性
|
||
|
### AutoJobTask
|
||
|
定时任务父类
|
||
|
```csharp
|
||
|
[JobDetail(JobId = "job_DatabasesBackup", GroupName = "system", Description = "数据库备份")]
|
||
|
[PeriodSeconds(60, RunOnStart = true, TriggerId = "trigger_DatabasesBackup")]
|
||
|
[DisallowConcurrentExecution]
|
||
|
public class DatabasesBackupJob : AutoJobTask
|
||
|
{
|
||
|
|
||
|
public override async Task Run(IJobExecutionContext context,IServiceProvider serviceProvider)
|
||
|
{
|
||
|
...
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
## 定时任务特性
|
||
|
### JobDetailAttribute
|
||
|
用于描述定时任务的作用
|
||
|
|
||
|
- JobId:任务ID
|
||
|
- GroupName:分组名称
|
||
|
- Description:描述
|
||
|
|
||
|
### CronAttribute
|
||
|
定时任务触发器,Cron表达式
|
||
|
|
||
|
- TriggerId:触发器ID
|
||
|
- Args:触发器参数
|
||
|
- Description:描述
|
||
|
- StartTime:开始时间
|
||
|
- EndTime:结束时间
|
||
|
- MaxNumberOfRuns:最大执行次数
|
||
|
- MaxNumberOfErrors:最大错误次数
|
||
|
- NumRetries:重试次数
|
||
|
- RetryTimeout:重试超时时间
|
||
|
- RunOnStart:是否在启动时执行
|
||
|
|
||
|
### PeriodSecondsAttribute
|
||
|
每隔x秒执行任务
|
||
|
|
||
|
- TriggerId:触发器ID
|
||
|
- Args:触发器参数
|
||
|
- Description:描述
|
||
|
- StartTime:开始时间
|
||
|
- EndTime:结束时间
|
||
|
- MaxNumberOfRuns:最大执行次数
|
||
|
- MaxNumberOfErrors:最大错误次数
|
||
|
- NumRetries:重试次数
|
||
|
- RetryTimeout:重试超时时间
|
||
|
- RunOnStart:是否在启动时执行
|
||
|
|
||
|
### PeriodMinutesAttribute
|
||
|
每隔x分钟执行任务
|
||
|
|
||
|
- TriggerId:触发器ID
|
||
|
- Args:触发器参数
|
||
|
- Description:描述
|
||
|
- StartTime:开始时间
|
||
|
- EndTime:结束时间
|
||
|
- MaxNumberOfRuns:最大执行次数
|
||
|
- MaxNumberOfErrors:最大错误次数
|
||
|
- NumRetries:重试次数
|
||
|
- RetryTimeout:重试超时时间
|
||
|
- RunOnStart:是否在启动时执行
|
||
|
|
||
|
### DailyAtAttribute
|
||
|
每天x点执行任务
|
||
|
|
||
|
- TriggerId:触发器ID
|
||
|
- Args:触发器参数
|
||
|
- Description:描述
|
||
|
- StartTime:开始时间
|
||
|
- EndTime:结束时间
|
||
|
- MaxNumberOfRuns:最大执行次数
|
||
|
- MaxNumberOfErrors:最大错误次数
|
||
|
- NumRetries:重试次数
|
||
|
- RetryTimeout:重试超时时间
|
||
|
- RunOnStart:是否在启动时执行
|
||
|
|