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.
86 lines
2.6 KiB
86 lines
2.6 KiB
using Hangfire;
|
|
using Hangfire.MySql;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
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();
|
|
|
|
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);
|
|
|
|
app.UseHangfireDashboard(pathMatch: "/job");
|
|
|
|
app.UseHangfireServer();
|
|
|
|
app.UseCors(_origins);
|
|
|
|
app.UseStaticFiles();
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapControllerRoute(
|
|
name: "default",
|
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
|
});
|
|
}
|
|
}
|
|
} |