Files
EmailBill/Service/Jobs/PeriodicBillJob.cs

34 lines
1012 B
C#
Raw Permalink Normal View History

2025-12-29 15:20:32 +08:00
using Quartz;
using Service.Transaction;
2025-12-29 15:20:32 +08:00
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();
2025-12-29 15:20:32 +08:00
logger.LogInformation("周期性账单检查任务执行完成");
}
catch (Exception ex)
{
logger.LogError(ex, "周期性账单检查任务执行出错");
throw; // 让 Quartz 知道任务失败
}
}
}