feat(archival): in DEBUG, archive only 25 lists and on startup

This commit is contained in:
Collin M. Barrett 2020-09-19 09:23:08 -05:00
parent 92cc505faa
commit cee379cf9f
2 changed files with 16 additions and 2 deletions

View file

@ -26,9 +26,18 @@ public Handler(IDirectoryApi directory)
public async Task<Unit> Handle(Command request, CancellationToken cancellationToken)
{
var r = new Random();
foreach (var list in (await _directory.GetListsAsync(cancellationToken)).OrderBy(_ => r.Next()))
var lists = (await _directory.GetListsAsync(cancellationToken)).OrderBy(_ => r.Next()).ToList();
int numToArchive;
#if DEBUG
numToArchive = 25;
#else
numToArchive = lists.Count;
#endif
for (var i = 0; i < numToArchive; i++)
{
new ArchiveList.Command(list.Id).EnqueueBackgroundJob();
new ArchiveList.Command(lists[i].Id).EnqueueBackgroundJob();
}
return Unit.Value;

View file

@ -33,7 +33,12 @@ public static void UseApplication(this IApplicationBuilder app)
private static void ScheduleArchival(this IApplicationBuilder app)
{
_ = app ?? throw new ArgumentNullException(nameof(app));
#if DEBUG
new EnqueueArchiveAllLists.Command().EnqueueBackgroundJob();
#else
new EnqueueArchiveAllLists.Command().AddOrUpdateRecurringJob(Cron.Daily);
#endif
}
}
}