55 lines
1.9 KiB
C#
55 lines
1.9 KiB
C#
using Hangfire;
|
|
using Hangfire.Dashboard.BasicAuthorization;
|
|
using Hangfire.MySql;
|
|
using Kurisu.AspNetCore.Startup;
|
|
|
|
namespace Dlhis.ScheduledTask
|
|
{
|
|
public class HangfirePack : BaseAppPack
|
|
{
|
|
public override bool IsBeforeUseRouting { get; }
|
|
|
|
public override void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddHangfire(configuration =>
|
|
{
|
|
var options = new MySqlStorageOptions
|
|
{
|
|
TablesPrefix = "Hangfire"
|
|
};
|
|
|
|
configuration.UseSimpleAssemblyNameTypeSerializer()
|
|
.UseRecommendedSerializerSettings()
|
|
.UseStorage(new MySqlStorage(Configuration.GetConnectionString("HangfireConnection"), options));
|
|
|
|
});
|
|
|
|
services.AddHangfireServer();
|
|
}
|
|
|
|
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
//支持可视化界面 ---任何一个用户都能够来访问;所以需要加一道屏障
|
|
app.UseHangfireDashboard("/hangfire", new DashboardOptions()
|
|
{
|
|
Authorization = new BasicAuthAuthorizationFilter[] {
|
|
new BasicAuthAuthorizationFilter(new BasicAuthAuthorizationFilterOptions(){
|
|
SslRedirect=false,
|
|
RequireSsl=false,
|
|
Users=new BasicAuthAuthorizationUser[]{
|
|
new BasicAuthAuthorizationUser(){
|
|
Login="admin",
|
|
PasswordClear="admin"
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
});
|
|
app.UseHangfireDashboard(); //使用hangfire面板
|
|
|
|
BackgroundJob.Enqueue(() => Console.WriteLine("This is a background job."));
|
|
}
|
|
}
|
|
}
|