新增定时账单功能
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
using System.Text;
|
||||
using FreeSql;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Scalar.AspNetCore;
|
||||
using Serilog;
|
||||
using Service.AppSettingModel;
|
||||
using WebApi;
|
||||
using Yitter.IdGenerator;
|
||||
|
||||
// 初始化雪花算法ID生成器
|
||||
@@ -97,6 +97,9 @@ builder.Services.AddSingleton(fsql);
|
||||
// 自动扫描注册服务和仓储
|
||||
builder.Services.AddServices();
|
||||
|
||||
// 配置 Quartz.NET 定时任务
|
||||
builder.AddScheduler();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
@@ -122,27 +125,4 @@ app.MapControllers();
|
||||
// 添加 SPA 回退路由(用于前端路由)
|
||||
app.MapFallbackToFile("index.html");
|
||||
|
||||
// 启动后台邮件抓取服务(必须只注册一次)
|
||||
app.Lifetime.ApplicationStarted.Register(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (app.Services.GetRequiredService<IEmailBackgroundService>() is not EmailBackgroundService emailService)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查是否已在运行,避免重复启动
|
||||
if (!emailService.IsBusy)
|
||||
{
|
||||
emailService.RunWorkerAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var logger = app.Services.GetRequiredService<ILogger<Program>>();
|
||||
logger.LogError(ex, "启动后台服务失败");
|
||||
}
|
||||
});
|
||||
|
||||
app.Run();
|
||||
|
||||
Reference in New Issue
Block a user