using Hangfire; using Hangfire.Dashboard.BasicAuthorization; using Hangfire.HttpJob; using Hangfire.MySql; using JiShe.CollectBus.Application; namespace JiShe.CollectBus.Host { public class Startup(IConfiguration configuration) { public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddApplication(); services.AddEndpointsApiExplorer(); services.AddSwaggerGen(); 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(); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseSwagger(); app.UseSwaggerUI(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); 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(endpoints => //{ // endpoints.MapRazorPages(); //}); app.UseConfiguredEndpoints(); } } }