You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
3.7 KiB
117 lines
3.7 KiB
using Hangfire;
|
|
using Hangfire.Dashboard.BasicAuthorization;
|
|
using Hangfire.MySql;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.OpenApi.Models;
|
|
using System;
|
|
using System.Transactions;
|
|
|
|
namespace JobServer
|
|
{
|
|
public class Startup
|
|
{
|
|
public Startup(IConfiguration configuration)
|
|
{
|
|
Configuration = configuration;
|
|
}
|
|
|
|
private readonly string _origins = "AllowAllHeaders";
|
|
public IConfiguration Configuration { get; }
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddCors(options => options.AddPolicy(_origins,
|
|
builder =>
|
|
{
|
|
builder.SetIsOriginAllowed(o => true).AllowAnyMethod().AllowAnyHeader().AllowCredentials();
|
|
})
|
|
);
|
|
|
|
services.AddHttpClient();
|
|
|
|
services.AddControllersWithViews();
|
|
|
|
services.AddSwaggerGen(c =>
|
|
{
|
|
c.SwaggerDoc("v1", new OpenApiInfo { Title = "JobServerApi", Version = "v1" });
|
|
});
|
|
services.AddSwaggerGenNewtonsoftSupport();
|
|
|
|
var connectionString = Configuration.GetConnectionString("HangfireConnection");
|
|
|
|
services.AddHangfire(configuration => configuration.UseStorage(new MySqlStorage(connectionString, new MySqlStorageOptions
|
|
{
|
|
TransactionIsolationLevel = IsolationLevel.ReadCommitted,
|
|
QueuePollInterval = TimeSpan.FromSeconds(15),
|
|
JobExpirationCheckInterval = TimeSpan.FromHours(1),
|
|
CountersAggregateInterval = TimeSpan.FromMinutes(5),
|
|
PrepareSchemaIfNecessary = true,
|
|
DashboardJobListLimit = 50000,
|
|
TransactionTimeout = TimeSpan.FromMinutes(1),
|
|
TablesPrefix = "Hangfire"
|
|
})));
|
|
}
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
else
|
|
{
|
|
app.UseExceptionHandler("/Error");
|
|
}
|
|
|
|
string basePath = this.Configuration.GetValue<String>("BasePath", "");
|
|
|
|
app.UsePathBase(basePath);
|
|
|
|
var options = new DashboardOptions
|
|
{
|
|
Authorization = new[] { new BasicAuthAuthorizationFilter(new BasicAuthAuthorizationFilterOptions
|
|
{
|
|
RequireSsl = false,
|
|
SslRedirect = false,
|
|
LoginCaseSensitive = true,
|
|
Users = new []
|
|
{
|
|
new BasicAuthAuthorizationUser
|
|
{
|
|
Login = Configuration["auth:usr"],
|
|
PasswordClear = Configuration["auth:pwd"]
|
|
}
|
|
}
|
|
}) }
|
|
};
|
|
|
|
app.UseHangfireDashboard("/job", options);
|
|
|
|
app.UseHangfireServer();
|
|
|
|
app.UseCors(_origins);
|
|
|
|
app.UseStaticFiles();
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapControllerRoute(
|
|
name: "default",
|
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
|
});
|
|
|
|
app.UseSwagger();
|
|
|
|
app.UseSwaggerUI(c =>
|
|
{
|
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", "JobServerApis");
|
|
});
|
|
}
|
|
}
|
|
} |