feat(archival): equally space archival jobs throughout the day to distribute resources

This commit is contained in:
Collin M. Barrett 2020-09-19 10:05:44 -05:00
parent eed80de6d2
commit 7f0ee525a2

View file

@ -29,15 +29,18 @@ public async Task<Unit> Handle(Command request, CancellationToken cancellationTo
var lists = (await _directory.GetListsAsync(cancellationToken)).OrderBy(_ => r.Next()).ToList();
int numToArchive;
TimeSpan spacing;
#if DEBUG
numToArchive = 25;
spacing = TimeSpan.FromSeconds(2.5);
#else
numToArchive = lists.Count;
spacing = TimeSpan.FromSeconds((double)86400 / lists.Count);
#endif
for (var i = 0; i < numToArchive; i++)
{
new ArchiveList.Command(lists[i].Id).EnqueueBackgroundJob();
new ArchiveList.Command(lists[i].Id).ScheduleBackgroundJob(i * spacing);
}
return Unit.Value;