Files
jinko.yikatong/Src/Dlhis.ScheduledTask/Packs/HangfirePack.cs

62 lines
1.8 KiB
C#

using Hangfire;
using Hangfire.Dashboard.BasicAuthorization;
using Hangfire.Redis.StackExchange;
using Kurisu.AspNetCore.Startup;
using StackExchange.Redis;
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((sp, config) =>
{
config.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseRedisStorage(sp.GetService<IConnectionMultiplexer>(), new RedisStorageOptions
{
Db = 5,
Prefix = "hangfire"
})
.UseSerilogLogProvider();
});
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 = "dlhis123"
}
}
})
}
});
app.UseHangfireDashboard();
}
}