правки по ревью, переменная lifetime типа TimeSpan

This commit is contained in:
Olga Nemt 2023-11-10 15:39:52 +05:00
parent de59cb5f85
commit 0735526c70
3 changed files with 6 additions and 5 deletions

View File

@ -61,9 +61,9 @@ namespace AsbCloudApp.Services
/// <summary>
/// Удаление отчетов, с момента загрузки которых прошло n дней
/// </summary>
/// <param name="days">период, за который отчеты хранятся на сервере и при превышении которого удаляются</param>
/// <param name="lifetime">период хранения на сервере скачанных отчетов</param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> DeleteAllOldReportsAsync(int days, CancellationToken token);
Task<int> DeleteAllOldReportsAsync(TimeSpan lifetime, CancellationToken token);
}
}

View File

@ -28,7 +28,7 @@ namespace AsbCloudInfrastructure.Background
protected override async Task Action(string id, IServiceProvider services, Action<string, double?> onProgressCallback, CancellationToken token)
{
var reportService = services.GetRequiredService<IReportService>();
await reportService.DeleteAllOldReportsAsync(-30, token);
await reportService.DeleteAllOldReportsAsync(new TimeSpan(30, 0, 0, 0), token);
}
}
}

View File

@ -190,10 +190,11 @@ namespace AsbCloudInfrastructure.Services
return generator;
}
public async Task<int> DeleteAllOldReportsAsync(int days, CancellationToken token)
public async Task<int> DeleteAllOldReportsAsync(TimeSpan lifetime, CancellationToken token)
{
var lifeTimeStartDate = DateTime.UtcNow.Date.Add(-lifetime);
var fileIds = db.ReportProperties
.Where(r => r.File.UploadDate.Date < DateTime.UtcNow.Date.AddDays(days))
.Where(r => r.File.UploadDate.Date < lifeTimeStartDate)
.Select(r => r.IdFile);
if (fileIds.Any())