forked from ddrilling/AsbCloudServer
правки по ревью, переменная lifetime типа TimeSpan
This commit is contained in:
parent
de59cb5f85
commit
0735526c70
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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