重构: 将 LogCleanupService 转为 Quartz Job 服务
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 22s
Docker Build & Deploy / Deploy to Production (push) Successful in 7s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s
Docker Build & Deploy / WeChat Notification (push) Successful in 1s

- 创建 LogCleanupJob 替代 LogCleanupService (BackgroundService)
- 在 Expand.cs 中注册 LogCleanupJob (每天凌晨2点执行, 保留30天日志)
- 从 Program.cs 移除 LogCleanupService 的 HostedService 注册
- 删除 Service/LogCleanupService.cs
- 删除 Service/PeriodicBillBackgroundService.cs (已无用的重复服务)

所有后台任务现在统一通过 Quartz.NET 管理, 支持运行时控制
This commit is contained in:
SunCheng
2026-01-28 11:19:23 +08:00
parent b71eadd4f9
commit 3ed9cf5ebd
26 changed files with 133 additions and 183 deletions

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Authorization;
using Service.Message;
namespace WebApi.Controllers;

View File

@@ -1,4 +1,6 @@
namespace WebApi.Controllers;
using Service.Message;
namespace WebApi.Controllers;
[ApiController]
[Route("api/[controller]/[action]")]

View File

@@ -1,4 +1,6 @@
namespace WebApi.Controllers;
using Service.Transaction;
namespace WebApi.Controllers;
/// <summary>
/// 周期性账单控制器

View File

@@ -1,3 +1,6 @@
using Service.AI;
using Service.Transaction;
namespace WebApi.Controllers;
[ApiController]

View File

@@ -1,4 +1,4 @@
using Quartz;
using Quartz;
using Service.Jobs;
namespace WebApi;
@@ -55,6 +55,17 @@ public static class Expand
.WithIdentity("DbBackupTrigger")
.WithCronSchedule("0 0 6 * * ?") // 每天早上6点执行
.WithDescription("每天早上6点执行数据库备份"));
// 配置日志清理任务 - 每天凌晨2点执行
var logCleanupJobKey = new JobKey("LogCleanupJob");
q.AddJob<LogCleanupJob>(opts => opts
.WithIdentity(logCleanupJobKey)
.WithDescription("日志清理任务"));
q.AddTrigger(opts => opts
.ForJob(logCleanupJobKey)
.WithIdentity("LogCleanupTrigger")
.WithCronSchedule("0 0 2 * * ?") // 每天凌晨2点执行
.WithDescription("每天凌晨2点执行日志清理(保留30天)"));
});
// 添加 Quartz Hosted Service

View File

@@ -124,9 +124,6 @@ builder.Services.AddSingleton(fsql);
// 自动扫描注册服务和仓储
builder.Services.AddServices();
// 注册日志清理后台服务
builder.Services.AddHostedService<LogCleanupService>();
// 配置 Quartz.NET 定时任务
builder.AddScheduler();