feat(archival): log enqueuing of archive job stats

This commit is contained in:
Collin M. Barrett 2020-09-19 12:46:37 -05:00
parent b1ba4dfb3d
commit 79421a443a
2 changed files with 10 additions and 5 deletions

View file

@ -5,6 +5,7 @@
using FilterLists.Archival.Infrastructure.Scheduling;
using FilterLists.SharedKernel.Apis.Clients;
using MediatR;
using Microsoft.Extensions.Logging;
namespace FilterLists.Archival.Application.Commands
{
@ -17,10 +18,12 @@ public class Command : IRequest
public class Handler : IRequestHandler<Command, Unit>
{
private readonly IDirectoryApi _directory;
private readonly ILogger _logger;
public Handler(IDirectoryApi directory)
public Handler(IDirectoryApi directory, ILogger<Handler> logger)
{
_directory = directory;
_logger = logger;
}
public async Task<Unit> Handle(Command request, CancellationToken cancellationToken)
@ -28,17 +31,18 @@ public async Task<Unit> Handle(Command request, CancellationToken cancellationTo
var r = new Random();
var lists = (await _directory.GetListsAsync(cancellationToken)).OrderBy(_ => r.Next()).ToList();
int numToArchive;
int archiveCount;
TimeSpan spacing;
#if DEBUG
numToArchive = 25;
archiveCount = 25;
spacing = TimeSpan.FromSeconds(2.5);
#else
numToArchive = lists.Count;
archiveCount = lists.Count;
spacing = TimeSpan.FromSeconds((double)86400 / lists.Count);
_logger.LogDebug("Enqueuing archival of {ArchiveCount} lists spaced {Spacing} seconds apart.", archiveCount, spacing.Seconds);
#endif
for (var i = 0; i < numToArchive; i++)
for (var i = 0; i < archiveCount; i++)
{
new ArchiveList.Command(lists[i].Id).ScheduleBackgroundJob(i * spacing);
}

View file

@ -10,6 +10,7 @@
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_CHAINED_BINARY_EXPRESSIONS/@EntryValue">CHOP_IF_LONG</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_CHAINED_METHOD_CALLS/@EntryValue">CHOP_IF_LONG</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_PARAMETERS_STYLE/@EntryValue">CHOP_IF_LONG</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Enqueuing/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Hangfire/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mediat/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Primariness/@EntryIndexedValue">True</s:Boolean>