优化结构
This commit is contained in:
parent
17e36f5a56
commit
17df6af4f0
@ -7,9 +7,8 @@ using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Application;
|
||||
using Volo.Abp.AspNetCore.Mvc;
|
||||
using Volo.Abp.AutoMapper;
|
||||
using Volo.Abp.BackgroundWorkers;
|
||||
using Volo.Abp.BackgroundWorkers.Hangfire;
|
||||
using Volo.Abp.Modularity;
|
||||
|
||||
namespace JiShe.CollectBus.Migration;
|
||||
@ -19,7 +18,6 @@ namespace JiShe.CollectBus.Migration;
|
||||
typeof(CollectBusMigrationApplicationContractsModule),
|
||||
typeof(AbpDddApplicationModule),
|
||||
typeof(AbpAutoMapperModule),
|
||||
typeof(AbpBackgroundWorkersHangfireModule),
|
||||
typeof(CollectBusFreeRedisModule),
|
||||
typeof(CollectBusFreeSqlModule),
|
||||
typeof(CollectBusIoTDbModule)
|
||||
@ -38,10 +36,10 @@ public class CollectBusMigrationApplicationModule : AbpModule
|
||||
public override async Task OnApplicationInitializationAsync(
|
||||
ApplicationInitializationContext context)
|
||||
{
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
var types = assembly.GetTypes().Where(t => typeof(ICollectWorker).IsAssignableFrom(t) && !t.IsInterface)
|
||||
.ToList();
|
||||
foreach (var type in types) await context.AddBackgroundWorkerAsync(type);
|
||||
//var assembly = Assembly.GetExecutingAssembly();
|
||||
//var types = assembly.GetTypes().Where(t => typeof(ICollectWorker).IsAssignableFrom(t) && !t.IsInterface)
|
||||
// .ToList();
|
||||
//foreach (var type in types) await context.AddBackgroundWorkerAsync(type);
|
||||
|
||||
//Task.Run(() =>
|
||||
//{
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
using AutoMapper;
|
||||
|
||||
namespace JiShe.CollectBus;
|
||||
|
||||
public class CollectBusMigrationlicationAutoMapperProfile : Profile
|
||||
{
|
||||
public CollectBusMigrationlicationAutoMapperProfile()
|
||||
{
|
||||
/* You can configure your AutoMapper mapping configuration here.
|
||||
* Alternatively, you can split your mapping configurations
|
||||
* into multiple profile classes for a better organization. */
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,11 @@
|
||||
using Hangfire;
|
||||
using Hangfire.Redis.StackExchange;
|
||||
//using Hangfire;
|
||||
//using Hangfire.Redis.StackExchange;
|
||||
using JiShe.CollectBus.Migration.Host.Hangfire;
|
||||
using JiShe.CollectBus.Migration.Host.HealthChecks;
|
||||
using JiShe.CollectBus.Migration.Host.Swaggers;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using StackExchange.Redis;
|
||||
@ -23,28 +25,28 @@ namespace JiShe.CollectBus.Migration.Host
|
||||
/// Configures the hangfire.
|
||||
/// </summary>
|
||||
/// <param name="context">The context.</param>
|
||||
private void ConfigureHangfire(ServiceConfigurationContext context)
|
||||
{
|
||||
var redisStorageOptions = new RedisStorageOptions()
|
||||
{
|
||||
Db = context.Services.GetConfiguration().GetValue<int>("Redis:HangfireDB")
|
||||
};
|
||||
//private void ConfigureHangfire(ServiceConfigurationContext context)
|
||||
//{
|
||||
// var redisStorageOptions = new RedisStorageOptions()
|
||||
// {
|
||||
// Db = context.Services.GetConfiguration().GetValue<int>("Redis:HangfireDB")
|
||||
// };
|
||||
|
||||
Configure<AbpBackgroundJobOptions>(options => { options.IsJobExecutionEnabled = false; });
|
||||
// Configure<AbpBackgroundJobOptions>(options => { options.IsJobExecutionEnabled = false; });
|
||||
|
||||
context.Services.AddHangfire(config =>
|
||||
{
|
||||
config.UseRedisStorage(
|
||||
context.Services.GetConfiguration().GetValue<string>("Redis:Configuration"), redisStorageOptions)
|
||||
.WithJobExpirationTimeout(TimeSpan.FromDays(7));
|
||||
var delaysInSeconds = new[] { 10, 60, 60 * 3 }; // 重试时间间隔
|
||||
const int Attempts = 3; // 重试次数
|
||||
config.UseFilter(new AutomaticRetryAttribute() { Attempts = Attempts, DelaysInSeconds = delaysInSeconds });
|
||||
//config.UseFilter(new AutoDeleteAfterSuccessAttribute(TimeSpan.FromDays(7)));
|
||||
config.UseFilter(new JobRetryLastFilter(Attempts));
|
||||
});
|
||||
context.Services.AddHangfireServer();
|
||||
}
|
||||
// context.Services.AddHangfire(config =>
|
||||
// {
|
||||
// config.UseRedisStorage(
|
||||
// context.Services.GetConfiguration().GetValue<string>("Redis:Configuration"), redisStorageOptions)
|
||||
// .WithJobExpirationTimeout(TimeSpan.FromDays(7));
|
||||
// var delaysInSeconds = new[] { 10, 60, 60 * 3 }; // 重试时间间隔
|
||||
// const int Attempts = 3; // 重试次数
|
||||
// config.UseFilter(new AutomaticRetryAttribute() { Attempts = Attempts, DelaysInSeconds = delaysInSeconds });
|
||||
// //config.UseFilter(new AutoDeleteAfterSuccessAttribute(TimeSpan.FromDays(7)));
|
||||
// config.UseFilter(new JobRetryLastFilter(Attempts));
|
||||
// });
|
||||
// context.Services.AddHangfireServer();
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the JWT authentication.
|
||||
@ -179,7 +181,7 @@ namespace JiShe.CollectBus.Migration.Host
|
||||
{
|
||||
options.IsEnabled = true;
|
||||
options.EntityHistorySelectors.AddAllEntities();
|
||||
options.ApplicationName = "JiShe.CollectBus";
|
||||
options.ApplicationName = "JiShe.CollectBus.Migration";
|
||||
}
|
||||
);
|
||||
|
||||
@ -245,27 +247,18 @@ namespace JiShe.CollectBus.Migration.Host
|
||||
/// <param name="configuration"></param>
|
||||
private void ConfigureHealthChecks(ServiceConfigurationContext context, IConfiguration configuration)
|
||||
{
|
||||
//if (!configuration.GetValue<bool>("HealthChecks:IsEnable")) return;
|
||||
//var cassandraConfig = new CassandraConfig();
|
||||
//configuration.GetSection("Cassandra").Bind(cassandraConfig);
|
||||
//context.Services.AddHealthChecks()
|
||||
// .AddMongoDb(configuration.GetConnectionString("Default"), "MongoDB", HealthStatus.Unhealthy)
|
||||
// .AddRedis(configuration.GetValue<string>("Redis:Configuration") ?? string.Empty, "Redis",
|
||||
// HealthStatus.Unhealthy)
|
||||
// .AddKafka(new Confluent.Kafka.ProducerConfig
|
||||
// {
|
||||
// BootstrapServers = configuration.GetValue<string>("Kafka:BootstrapServers")
|
||||
// }, "Kafka", failureStatus: HealthStatus.Unhealthy)
|
||||
if (!configuration.GetValue<bool>("HealthChecks:IsEnable")) return;
|
||||
context.Services.AddHealthChecks()
|
||||
.AddRedis(configuration.GetValue<string>("Redis:Configuration") ?? string.Empty, "Redis",
|
||||
HealthStatus.Unhealthy)
|
||||
.AddCheck<IoTdbHealthCheck>("IoTDB");
|
||||
|
||||
// //.AddCheck<CassandraHealthCheck>("Cassandra")
|
||||
// .AddCheck<IoTdbHealthCheck>("IoTDB");
|
||||
|
||||
//context.Services
|
||||
// .AddHealthChecksUI(options =>
|
||||
// {
|
||||
// options.AddHealthCheckEndpoint("JiSheCollectBus", "/health"); // 映射本地端点
|
||||
// })
|
||||
// .AddInMemoryStorage();
|
||||
context.Services
|
||||
.AddHealthChecksUI(options =>
|
||||
{
|
||||
options.AddHealthCheckEndpoint("JiSheCollectBusMigration", "/health"); // 映射本地端点
|
||||
})
|
||||
.AddInMemoryStorage();
|
||||
|
||||
|
||||
}
|
||||
@ -5,6 +5,7 @@ using JiShe.CollectBus.Migration.Host.Swaggers;
|
||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
using Swashbuckle.AspNetCore.SwaggerUI;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.AspNetCore;
|
||||
using Volo.Abp.AspNetCore.Authentication.JwtBearer;
|
||||
using Volo.Abp.AspNetCore.Serilog;
|
||||
using Volo.Abp.Autofac;
|
||||
@ -26,8 +27,7 @@ namespace JiShe.CollectBus.Migration.Host
|
||||
typeof(AbpSwashbuckleModule),
|
||||
typeof(AbpTimingModule),
|
||||
typeof(CollectBusMigrationApplicationModule),
|
||||
typeof(AbpCachingStackExchangeRedisModule),
|
||||
typeof(AbpBackgroundWorkersHangfireModule)
|
||||
typeof(AbpCachingStackExchangeRedisModule)
|
||||
)]
|
||||
public partial class CollectBusMigrationHostModule : AbpModule
|
||||
{
|
||||
@ -40,12 +40,12 @@ namespace JiShe.CollectBus.Migration.Host
|
||||
var configuration = context.Services.GetConfiguration();
|
||||
ConfigureCache(context);
|
||||
ConfigureSwaggerServices(context, configuration);
|
||||
ConfigureNetwork(context, configuration);
|
||||
//ConfigureNetwork(context, configuration);
|
||||
ConfigureJwtAuthentication(context, configuration);
|
||||
ConfigureHangfire(context);
|
||||
//ConfigureHangfire(context);
|
||||
ConfigureAuditLog(context);
|
||||
ConfigureCustom(context, configuration);
|
||||
//ConfigureHealthChecks(context, configuration);
|
||||
ConfigureHealthChecks(context, configuration);
|
||||
Configure<AbpClockOptions>(options => { options.Kind = DateTimeKind.Local; });
|
||||
|
||||
Configure<ServerApplicationOptions>(options =>
|
||||
@ -84,13 +84,13 @@ namespace JiShe.CollectBus.Migration.Host
|
||||
options.DefaultModelsExpandDepth(-1);
|
||||
});
|
||||
}
|
||||
app.UseAuditing();
|
||||
//app.UseAuditing();
|
||||
app.UseAbpSerilogEnrichers();
|
||||
app.UseUnitOfWork();
|
||||
app.UseHangfireDashboard("/hangfire", new DashboardOptions
|
||||
{
|
||||
IgnoreAntiforgeryToken = true
|
||||
});
|
||||
//app.UseHangfireDashboard("/hangfire", new DashboardOptions
|
||||
//{
|
||||
// IgnoreAntiforgeryToken = true
|
||||
//});
|
||||
app.UseConfiguredEndpoints(endpoints =>
|
||||
{
|
||||
if (!configuration.GetValue<bool>("HealthChecks:IsEnable")) return;
|
||||
@ -27,7 +27,7 @@
|
||||
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="9.0.0" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.UI.InMemory.Storage" Version="9.0.0" />
|
||||
|
||||
<PackageReference Include="Hangfire.Redis.StackExchange" Version="1.9.4" />
|
||||
<!--<PackageReference Include="Hangfire.Redis.StackExchange" Version="1.9.4" />-->
|
||||
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="9.0.0" />
|
||||
<PackageReference Include="Serilog" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
|
||||
@ -43,7 +43,7 @@
|
||||
<PackageReference Include="Volo.Abp.AspNetCore.Authentication.JwtBearer" Version="8.3.3" />
|
||||
<PackageReference Include="Volo.Abp.AspNetCore.Serilog" Version="8.3.3" />
|
||||
<PackageReference Include="Volo.Abp.Autofac" Version="8.3.3" />
|
||||
<PackageReference Include="Volo.Abp.BackgroundWorkers.Hangfire" Version="8.3.3" />
|
||||
<!--<PackageReference Include="Volo.Abp.BackgroundWorkers.Hangfire" Version="8.3.3" />-->
|
||||
|
||||
<PackageReference Include="Volo.Abp.Caching.StackExchangeRedis" Version="8.3.3" />
|
||||
<PackageReference Include="Volo.Abp.Swashbuckle" Version="8.3.3" />
|
||||
|
||||
@ -16,6 +16,18 @@ public class Program
|
||||
/// <returns></returns>
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
//var builder = WebApplication.CreateBuilder(args);
|
||||
//builder.Host
|
||||
// .UseContentRoot(Directory.GetCurrentDirectory())
|
||||
// .UseSerilog((context, loggerConfiguration) =>
|
||||
// {
|
||||
// loggerConfiguration.ReadFrom.Configuration(context.Configuration);
|
||||
// })
|
||||
// .UseAutofac();
|
||||
//var app = builder.Build();
|
||||
//await app.InitializeApplicationAsync();
|
||||
//await app.RunAsync();
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Host.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseSerilog((context, loggerConfiguration) =>
|
||||
@ -24,6 +36,10 @@ public class Program
|
||||
})
|
||||
.UseAutofac();
|
||||
var configuration = builder.Configuration;
|
||||
await builder.AddApplicationAsync<CollectBusMigrationHostModule>(options =>
|
||||
{
|
||||
//options.PlugInSources.AddFolder((configuration["PlugInFolder"].IsNullOrWhiteSpace() ? Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins") : configuration["PlugInFolder"]) ?? string.Empty);
|
||||
});
|
||||
var app = builder.Build();
|
||||
await app.InitializeApplicationAsync();
|
||||
await app.RunAsync();
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"profiles": {
|
||||
"JiShe.CollectBus.Host": {
|
||||
"JiShe.CollectBus.Migration.Host": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:44316",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user