2024-11-12 18:18:43 +08:00
|
|
|
|
using Hangfire;
|
|
|
|
|
|
using Hangfire.Dashboard.BasicAuthorization;
|
|
|
|
|
|
using Hangfire.HttpJob;
|
|
|
|
|
|
using Hangfire.MySql;
|
2024-11-13 00:30:24 +08:00
|
|
|
|
using JiShe.CollectBus.Application;
|
2024-11-12 18:18:43 +08:00
|
|
|
|
|
|
|
|
|
|
namespace JiShe.CollectBus.Host
|
2024-11-08 17:21:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
public class Startup(IConfiguration configuration)
|
|
|
|
|
|
{
|
|
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
|
|
{
|
|
|
|
|
|
services.AddControllers();
|
2024-11-13 17:50:52 +08:00
|
|
|
|
services.AddApplication<JiSheCollectBusApplicationModule>();
|
2024-11-08 17:21:49 +08:00
|
|
|
|
services.AddEndpointsApiExplorer();
|
|
|
|
|
|
services.AddSwaggerGen();
|
2024-11-12 18:18:43 +08:00
|
|
|
|
services.AddHangfire(config =>
|
|
|
|
|
|
{
|
|
|
|
|
|
config.SetDataCompatibilityLevel(CompatibilityLevel.Version_180)
|
|
|
|
|
|
.UseSimpleAssemblyNameTypeSerializer()
|
|
|
|
|
|
.UseRecommendedSerializerSettings();
|
|
|
|
|
|
|
|
|
|
|
|
config.UseStorage(
|
|
|
|
|
|
new MySqlStorage(
|
|
|
|
|
|
configuration.GetConnectionString("Default"),
|
|
|
|
|
|
new MySqlStorageOptions
|
|
|
|
|
|
{
|
|
|
|
|
|
QueuePollInterval = TimeSpan.FromSeconds(15), //- 作业队列轮询间隔。默认值为15秒。
|
|
|
|
|
|
JobExpirationCheckInterval = TimeSpan.FromHours(1), //- 作业到期检查间隔(管理过期记录)。默认值为1小时。
|
|
|
|
|
|
CountersAggregateInterval = TimeSpan.FromMinutes(5), //- 聚合计数器的间隔。默认为5分钟。
|
|
|
|
|
|
PrepareSchemaIfNecessary = true, //- 如果设置为true,则创建数据库表。默认是true。
|
|
|
|
|
|
DashboardJobListLimit = 50000, //- 仪表板作业列表限制。默认值为50000。
|
|
|
|
|
|
TransactionTimeout = TimeSpan.FromMinutes(1), //- 交易超时。默认为1分钟。
|
|
|
|
|
|
}));
|
|
|
|
|
|
config.UseHangfireHttpJob();
|
|
|
|
|
|
});
|
|
|
|
|
|
services.AddHangfireServer();
|
2024-11-08 17:21:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
|
|
|
|
{
|
2024-11-13 17:50:52 +08:00
|
|
|
|
|
2024-11-08 17:21:49 +08:00
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
|
|
{
|
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
|
app.UseSwagger();
|
|
|
|
|
|
app.UseSwaggerUI();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
|
app.UseStaticFiles();
|
|
|
|
|
|
|
|
|
|
|
|
app.UseRouting();
|
|
|
|
|
|
|
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
2024-11-12 18:18:43 +08:00
|
|
|
|
var dashboardOptions = new DashboardOptions();
|
|
|
|
|
|
|
|
|
|
|
|
if (env.IsProduction())
|
|
|
|
|
|
dashboardOptions = new DashboardOptions
|
|
|
|
|
|
{
|
|
|
|
|
|
Authorization = new[]
|
|
|
|
|
|
{
|
2024-11-13 17:50:52 +08:00
|
|
|
|
new BasicAuthAuthorizationFilter(new BasicAuthAuthorizationFilterOptions
|
|
|
|
|
|
{
|
|
|
|
|
|
SslRedirect = false,
|
|
|
|
|
|
RequireSsl = false,
|
|
|
|
|
|
LoginCaseSensitive = false,
|
|
|
|
|
|
Users =
|
|
|
|
|
|
[
|
|
|
|
|
|
new BasicAuthAuthorizationUser
|
|
|
|
|
|
{
|
|
|
|
|
|
Login = "admin",
|
|
|
|
|
|
PasswordClear = "lixiao1980"
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2024-11-12 18:18:43 +08:00
|
|
|
|
};
|
|
|
|
|
|
app.UseHangfireDashboard("/hangfire", dashboardOptions);
|
|
|
|
|
|
|
2024-11-13 17:50:52 +08:00
|
|
|
|
//app.UseEndpoints(endpoints =>
|
|
|
|
|
|
//{
|
|
|
|
|
|
// endpoints.MapRazorPages();
|
|
|
|
|
|
//});
|
|
|
|
|
|
app.UseConfiguredEndpoints();
|
2024-11-08 17:21:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|