94 lines
3.5 KiB
C#
Raw Normal View History

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;
using JiShe.CollectBus.Core;
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();
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-13 00:30:24 +08:00
services.AddApplication<JiSheCollectBusApplicationModule>();
2024-11-08 17:21:49 +08:00
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
2024-11-13 00:30:24 +08:00
app.InitializeApplication();
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[]
{
new BasicAuthAuthorizationFilter(new BasicAuthAuthorizationFilterOptions
{
SslRedirect = false,
RequireSsl = false,
LoginCaseSensitive = false,
Users =
[
new BasicAuthAuthorizationUser
{
Login = "admin",
PasswordClear = "lixiao1980"
}
]
})
},
};
}
app.UseHangfireDashboard("/hangfire", dashboardOptions);
app.UseEndpoints(endpoint =>
{
endpoint.MapControllers();
});
2024-11-13 00:30:24 +08:00
2024-11-08 17:21:49 +08:00
}
}
}