68 lines
2.2 KiB
C#
68 lines
2.2 KiB
C#
using Dlhis.ScheduledTask.Configurations;
|
|
using Dlhis.ScheduledTask.Job;
|
|
using Hangfire;
|
|
using Hangfire.Dashboard.BasicAuthorization;
|
|
using Hangfire.MySql;
|
|
using Kurisu.AspNetCore.Startup;
|
|
|
|
|
|
namespace Dlhis.ScheduledTask.Packs;
|
|
|
|
public class HangfirePack : BaseAppPack
|
|
{
|
|
public override bool IsBeforeUseRouting { get; }
|
|
|
|
public override void ConfigureServices(IServiceCollection services)
|
|
{
|
|
|
|
services.Configure<ServiceSettings>(Configuration.GetSection("ServiceSettings"));
|
|
services.AddHangfire(configuration =>
|
|
{
|
|
var options = new MySqlStorageOptions
|
|
{
|
|
TablesPrefix = "Hangfire"
|
|
};
|
|
|
|
configuration.UseSimpleAssemblyNameTypeSerializer()
|
|
.UseRecommendedSerializerSettings()
|
|
.UseStorage(new MySqlStorage(Configuration.GetConnectionString("HangfireConnection"), options));
|
|
|
|
});
|
|
services.UseHangfireto();
|
|
services.AddHangfireServer();
|
|
}
|
|
|
|
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
|
|
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();
|
|
|
|
BackgroundJob.Enqueue(() => Console.WriteLine("This is a background job."));
|
|
RecurringJob.AddOrUpdate<SyncOrgInfoJob>("SyncOrgInfoJob_id", s => s.SyncOrgInfo(), "0 0 0 * * ?");
|
|
RecurringJob.AddOrUpdate<SyncPositionJob>("SyncPositionJob_id", s => s.SyncPositionInfo(), "0 0 1 * * ?");
|
|
RecurringJob.AddOrUpdate<SyncPersonJob>("SyncPersonJob_id", s => s.SyncPersonInfo(), "0 0 2 * * ?");
|
|
}
|
|
}
|