引入
using Hangfire;
using Hangfire.AspNetCore;
using Hangfire.Storage;
using Hangfire.MySql.Core;
Hangfire持久化我这边配置的是mysql
Startup的 ConfigureServices 注册
var storage = new MySqlStorage(sysOptionConfig.YsWebconfig.DiseaseJobConnection
, new MySqlStorageOptions { PrepareSchemaIfNecessary = true, TablePrefix = “Disease” });
//定时任务
services.AddHangfire(config=> {
config.UseStorage(storage);
});
Configure方法内配置使用
//添加面板的打开权限。不是所有人都可以打开面板。可以操作后台任务。
app.UseHangfireDashboard("/ysjob", new DashboardOptions()
{
Authorization = new[] { new HangFireAuthorizeFilter() }
});
app.UseHangfireServer();
运行起来会创建表
sysOptionConfig.YsWebconfig.DiseaseJobConnection 是mysql链接字符串
站点运行起来 /ysjob 看状态