62 lines
1.8 KiB
C#
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 void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddHangfire((sp, config) =>
|
|
{
|
|
config.UseSimpleAssemblyNameTypeSerializer()
|
|
.UseRecommendedSerializerSettings()
|
|
.UseRedisStorage(sp.GetService<IConnectionMultiplexer>(), new RedisStorageOptions
|
|
{
|
|
Db = 5,
|
|
Prefix = "hangfire",
|
|
InvisibilityTimeout = TimeSpan.FromHours(2),
|
|
SucceededListSize = 5000,
|
|
})
|
|
.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();
|
|
}
|
|
}
|