Files
EmailBill/Service/Jobs/PeriodicBillJob.cs
SunCheng 3ed9cf5ebd
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
重构: 将 LogCleanupService 转为 Quartz Job 服务
- 创建 LogCleanupJob 替代 LogCleanupService (BackgroundService)
- 在 Expand.cs 中注册 LogCleanupJob (每天凌晨2点执行, 保留30天日志)
- 从 Program.cs 移除 LogCleanupService 的 HostedService 注册
- 删除 Service/LogCleanupService.cs
- 删除 Service/PeriodicBillBackgroundService.cs (已无用的重复服务)

所有后台任务现在统一通过 Quartz.NET 管理, 支持运行时控制
2026-01-28 11:19:23 +08:00

34 lines
1012 B
C#

using Quartz;
using Service.Transaction;
namespace Service.Jobs;
/// <summary>
/// 周期性账单定时任务
/// </summary>
[DisallowConcurrentExecution] // 防止并发执行
public class PeriodicBillJob(
IServiceProvider serviceProvider,
ILogger<PeriodicBillJob> logger) : IJob
{
public async Task Execute(IJobExecutionContext context)
{
try
{
logger.LogInformation("开始执行周期性账单检查任务");
// 执行周期性账单检查
using var scope = serviceProvider.CreateScope();
var periodicService = scope.ServiceProvider.GetRequiredService<ITransactionPeriodicService>();
await periodicService.ExecutePeriodicBillsAsync();
logger.LogInformation("周期性账单检查任务执行完成");
}
catch (Exception ex)
{
logger.LogError(ex, "周期性账单检查任务执行出错");
throw; // 让 Quartz 知道任务失败
}
}
}