62 lines
1.8 KiB
C#
62 lines
1.8 KiB
C#
using Hangfire;
|
|
using Hangfire.Dashboard.BasicAuthorization;
|
|
using Hangfire.MySql;
|
|
using Kurisu.AspNetCore.Startup;
|
|
|
|
|
|
namespace Dlhis.ScheduledTask.Packs;
|
|
|
|
public class HangfirePack : BaseAppPack
|
|
{
|
|
public override int Order => 990;
|
|
|
|
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)
|
|
{
|
|
GlobalConfiguration.Configuration.UseActivator(new ContainerJobActivator(app.ApplicationServices));
|
|
|
|
app.UseHangfireDashboard("/hangfire", new DashboardOptions
|
|
{
|
|
AppPath = null,
|
|
DashboardTitle = "hangfire",
|
|
Authorization = new[]
|
|
{
|
|
new BasicAuthAuthorizationFilter(new BasicAuthAuthorizationFilterOptions
|
|
{
|
|
RequireSsl = false,
|
|
SslRedirect = false,
|
|
Users = new []
|
|
{
|
|
new BasicAuthAuthorizationUser
|
|
{
|
|
Login ="admin",
|
|
PasswordClear = "admin"
|
|
}
|
|
}
|
|
})
|
|
}
|
|
});
|
|
|
|
app.UseHangfireDashboard();
|
|
}
|
|
}
|