forked from ddrilling/AsbCloudServer
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:
commit
3451d7ca98
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user