fix 删除日志try
This commit is contained in:
@@ -7,25 +7,35 @@ namespace Dlhis.ScheduledTask.CommonJobs;
|
||||
public class DelApiLogTaskJob
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly Logger<DelApiLogTaskJob> _logger;
|
||||
|
||||
public DelApiLogTaskJob(IDbContext dbContext)
|
||||
public DelApiLogTaskJob(IDbContext dbContext, Logger<DelApiLogTaskJob> logger)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task RunAsync()
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
DateTime todayStart = now.Date;
|
||||
DateTime threeDaysAgoStart = todayStart.AddDays(-3);
|
||||
try
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
DateTime todayStart = now.Date;
|
||||
DateTime threeDaysAgoStart = todayStart.AddDays(-3);
|
||||
|
||||
var logs = await _dbContext.ChangeDb("log")
|
||||
.Queryable<ApiLogEntity>()
|
||||
.Where(x => x._ts<= threeDaysAgoStart)
|
||||
.OrderBy(x =>x._ts,OrderByType.Asc)
|
||||
.ToListAsync();
|
||||
var logs = await _dbContext.ChangeDb("log")
|
||||
.Queryable<ApiLogEntity>()
|
||||
.Where(x => x._ts <= threeDaysAgoStart)
|
||||
.OrderBy(x => x._ts, OrderByType.Asc)
|
||||
.ToListAsync();
|
||||
|
||||
await _dbContext.ChangeDb("log").DeleteReallyAsync(logs);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "删除日志异常:{message}", ex.Message);
|
||||
}
|
||||
|
||||
await _dbContext.ChangeDb("log").DeleteReallyAsync(logs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user