新增rss功能
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
namespace Yes.Blog
|
||||
|
||||
namespace Yes.Blog
|
||||
{
|
||||
public static class DependencyInjection
|
||||
{
|
||||
@@ -30,6 +31,8 @@
|
||||
|
||||
services.AddEndpointsApiExplorer();
|
||||
|
||||
services.AddHangfire(configuration);
|
||||
|
||||
services.AddOpenApi(options =>
|
||||
{
|
||||
options.AddDocumentTransformer((document, context, cancellationToken) =>
|
||||
@@ -240,7 +243,7 @@
|
||||
|
||||
}
|
||||
|
||||
|
||||
app.MapHangfireDashboard();
|
||||
|
||||
return app;
|
||||
}
|
||||
@@ -273,5 +276,63 @@
|
||||
return app;
|
||||
}
|
||||
|
||||
|
||||
public static IServiceCollection AddHangfire(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
Enum.TryParse(configuration["DatabaseType"], out DatabaseTypeEnum databaseType);
|
||||
var connectionString = configuration["ConnectionString"] ?? "";
|
||||
var dbName = configuration["DatabaseName"] ?? "";
|
||||
|
||||
var builder = ConnectionStringBuilderFactory.CreateStringBuilder(databaseType, connectionString);
|
||||
builder.SetDatabaseName(dbName);
|
||||
|
||||
connectionString = builder.GetConnectionString();
|
||||
|
||||
// Add Hangfire services
|
||||
services.AddHangfire(config =>
|
||||
{
|
||||
switch (databaseType)
|
||||
{
|
||||
case DatabaseTypeEnum.SqlServer:
|
||||
config.UseSqlServerStorage(connectionString);
|
||||
break;
|
||||
case DatabaseTypeEnum.MySql:
|
||||
config.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"
|
||||
}));
|
||||
break;
|
||||
case DatabaseTypeEnum.PostgreSQL:
|
||||
config.UsePostgreSqlStorage(c =>c.UseNpgsqlConnection(connectionString));
|
||||
break;
|
||||
default:
|
||||
throw new InvalidOperationException($"Unsupported database type: {databaseType}");
|
||||
}
|
||||
|
||||
config.SetDataCompatibilityLevel(CompatibilityLevel.Version_180).UseSimpleAssemblyNameTypeSerializer().UseRecommendedSerializerSettings();
|
||||
});
|
||||
|
||||
|
||||
// Add the processing server as IHostedService
|
||||
services.AddHangfireServer();
|
||||
|
||||
|
||||
// var minute = 60;
|
||||
//int.TryParse(configuration["DatabaseName"], out minute);
|
||||
// RecurringJob.AddOrUpdate<RssGenerationJob>("dynamic-job", x => x.Execute(), Cron.Minutely);
|
||||
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user