Merge branch 'feature/#23919905-drop-all-old-reports' of http://test.digitaldrilling.ru:8080/DDrilling/AsbCloudServer into feature/#23919905-drop-all-old-reports

This commit is contained in:
ngfrolov 2023-11-10 16:23:58 +05:00
commit 3451d7ca98
Signed by: ng.frolov
GPG Key ID: E99907A0357B29A7
3 changed files with 7 additions and 6 deletions

View File

@ -59,11 +59,11 @@ namespace AsbCloudApp.Services
Task<IEnumerable<ReportPropertiesDto>> GetAllReportsByWellAsync(int idWell, CancellationToken token);
/// <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())