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.
2.1 KiB
2.1 KiB
LINGYUN.Abp.BackgroundJobs.Hangfire
English | 简体中文
1. 介绍
LINGYUN.Abp.BackgroundJobs.Hangfire 是基于 Hangfire 实现的ABP后台作业模块。它提供了一个可靠的后台作业执行框架,支持即时任务、延迟任务和周期性任务的执行。
2. 功能特性
- 支持即时任务执行
- 支持延迟任务执行
- 支持周期性任务(使用Cron表达式)
- 与ABP后台作业系统无缝集成
- 支持作业执行状态跟踪
- 支持作业重试机制
3. 安装
dotnet add package LINGYUN.Abp.BackgroundJobs.Hangfire
4. 使用方法
- 添加
AbpBackgroundJobsHangfireModule到模块依赖中:
[DependsOn(typeof(AbpBackgroundJobsHangfireModule))]
public class YourModule : AbpModule
{
}
- 配置后台作业:
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpBackgroundJobOptions>(options =>
{
options.IsJobExecutionEnabled = true; // 启用作业执行
});
}
- 使用后台作业:
public class YourService
{
private readonly IBackgroundJobManager _backgroundJobManager;
public YourService(IBackgroundJobManager backgroundJobManager)
{
_backgroundJobManager = backgroundJobManager;
}
public async Task CreateJobAsync()
{
// 创建即时任务
await _backgroundJobManager.EnqueueAsync(new YourArgs());
// 创建延迟任务
await _backgroundJobManager.EnqueueAsync(
new YourArgs(),
delay: TimeSpan.FromMinutes(5)
);
// 创建周期性任务
await _backgroundJobManager.EnqueueAsync(
"0 0 * * *", // Cron表达式:每天0点执行
new YourArgs()
);
}
}
5. 配置项
5.1 作业配置
AbpBackgroundJobOptions.IsJobExecutionEnabled: 是否启用作业执行。默认值:true
6. 依赖项
- Volo.Abp.BackgroundJobs
- Hangfire.Core
- Hangfire.AspNetCore