diff --git a/src/Oms.Application/Workers/XhsScheduledPublishWorker.cs b/src/Oms.Application/Workers/XhsScheduledPublishWorker.cs index fb1cfa5..8c8b63b 100644 --- a/src/Oms.Application/Workers/XhsScheduledPublishWorker.cs +++ b/src/Oms.Application/Workers/XhsScheduledPublishWorker.cs @@ -1,3 +1,4 @@ +using Fake.UnitOfWork; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; @@ -53,6 +54,9 @@ public class XhsScheduledPublishWorker : BackgroundService private async Task ProcessDueAsync(CancellationToken cancellationToken) { using var scope = _scopeFactory.CreateScope(); + var unitOfWorkManager = scope.ServiceProvider.GetRequiredService(); + using var unitOfWork = unitOfWorkManager.Begin(); + var publishRecordRepository = scope.ServiceProvider.GetRequiredService(); var publishService = scope.ServiceProvider.GetRequiredService(); @@ -81,5 +85,7 @@ public class XhsScheduledPublishWorker : BackgroundService record.Id, task.Id); } + + await unitOfWork.CompleteAsync(cancellationToken); } } diff --git a/src/SimpleAdmin.Api/Program.cs b/src/SimpleAdmin.Api/Program.cs index c76523e..39bf160 100644 --- a/src/SimpleAdmin.Api/Program.cs +++ b/src/SimpleAdmin.Api/Program.cs @@ -1,11 +1,23 @@ using Serilog; using SimpleAdmin.Api; +var builder = WebApplication.CreateSlimBuilder(args); +var configuration = builder.Configuration; +builder.Configuration.AddConsul("idwms/common", source => source.ReloadOnChange = true); +builder.Configuration.AddConsul("idwms/admin", source => source.ReloadOnChange = true); +Log.Logger = new LoggerConfiguration() + .ReadFrom.Configuration(configuration) + .CreateLogger(); + try { - var builder = SimpleAdminApiBootstrap.CreateBuilder(args); - var app = SimpleAdminApiBootstrap.BuildApplication(builder); - await app.RunAsync(); + builder.WebHost.UseUrls(builder.Configuration.GetSection("App:Urls").Get() ?? []); + builder.Host.UseAutofac().UseSerilog(); + builder.Services.AddApplication(); + + var app = builder.Build(); + app.InitializeApplication(); + app.Run(); } catch (Exception ex) { @@ -14,6 +26,4 @@ catch (Exception ex) finally { Log.CloseAndFlush(); -} - -public partial class Program; +} \ No newline at end of file diff --git a/src/SimpleAdmin.Api/SimpleAdminApiModule.cs b/src/SimpleAdmin.Api/SimpleAdminApiModule.cs index c5d1a67..ffebfc8 100644 --- a/src/SimpleAdmin.Api/SimpleAdminApiModule.cs +++ b/src/SimpleAdmin.Api/SimpleAdminApiModule.cs @@ -4,7 +4,6 @@ using Fake.Modularity; using Fake.Rbac.Application; using Fake.Rbac.Infrastructure; using Fake.AspNetCore.Auditing; -using Fake.AspNetCore.Authentication; using Fake.AspNetCore.ExceptionHandling; using Fake.AspNetCore.Newtonsoft; using Fake.AspNetCore.Swagger; @@ -25,6 +24,7 @@ namespace SimpleAdmin.Api; typeof(OmsSqlSugarCoreModule), typeof(FakeRbacApplicationModule), typeof(FakeRbacInfrastructureModule), + typeof(FakeAspNetCoreModule), typeof(FakeSerilogModule) )] public class SimpleAdminApiModule : FakeModule @@ -90,6 +90,8 @@ public class SimpleAdminApiModule : FakeModule options.KnownNetworks.Clear(); options.KnownProxies.Clear(); }); + + services.AddFeiShuNotification(); } public override void ConfigureApplication(ApplicationConfigureContext context) @@ -122,21 +124,6 @@ public class SimpleAdminApiModule : FakeModule // 端点映射 app.MapControllers(); - var shouldSendStartupNotification = - !app.Environment.IsEnvironment("Testing") && - app.Configuration.GetValue("App:SendStartupNotification", true); - if (!shouldSendStartupNotification) - { - return; - } - - try - { - app.Services.GetRequiredService().Send("Application started"); - } - catch (Exception ex) - { - app.Logger.LogWarning(ex, "Failed to send startup notification."); - } + app.Services.GetRequiredService().Send("Application started"); } }