71 lines
2.0 KiB
C#
71 lines
2.0 KiB
C#
using Dlhis.ScheduledTask.SyncSapInfo.Job;
|
|
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 => 999;
|
|
|
|
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();
|
|
|
|
#region 周期任务
|
|
//0:00
|
|
RecurringJob.AddOrUpdate<SyncOrganizationJob>("SysSap", s => s.SyncOrgInfo(), "30 * * * * ?", new RecurringJobOptions
|
|
{
|
|
TimeZone = TimeZoneInfo.Local
|
|
});
|
|
#endregion
|
|
}
|
|
}
|