refactor: Move log janitor to ServiceCommand

pull/76/head
Robert Dailey 3 years ago
parent 8e3630608c
commit 9a736426ce

@ -11,6 +11,7 @@ namespace Recyclarr.Command;
public abstract class ServiceCommand : ICommand, IServiceCommand public abstract class ServiceCommand : ICommand, IServiceCommand
{ {
private readonly IMigrationExecutor _migration; private readonly IMigrationExecutor _migration;
private readonly ILogJanitor _logJanitor;
[CommandOption("preview", 'p', Description = [CommandOption("preview", 'p', Description =
"Only display the processed markdown results without making any API calls.")] "Only display the processed markdown results without making any API calls.")]
@ -29,9 +30,10 @@ public abstract class ServiceCommand : ICommand, IServiceCommand
public abstract string CacheStoragePath { get; } public abstract string CacheStoragePath { get; }
public abstract string Name { get; } public abstract string Name { get; }
protected ServiceCommand(IMigrationExecutor migration) protected ServiceCommand(IMigrationExecutor migration, ILogJanitor logJanitor)
{ {
_migration = migration; _migration = migration;
_logJanitor = logJanitor;
} }
public async ValueTask ExecuteAsync(IConsole console) public async ValueTask ExecuteAsync(IConsole console)
@ -46,6 +48,8 @@ public abstract class ServiceCommand : ICommand, IServiceCommand
// Initialize command services and execute business logic (system environment changes should be done by this // Initialize command services and execute business logic (system environment changes should be done by this
// point) // point)
await Process(); await Process();
_logJanitor.DeleteOldestLogFiles(20);
} }
private void PerformMigrations() private void PerformMigrations()

@ -29,11 +29,6 @@ internal static class Program
.Build() .Build()
.RunAsync(); .RunAsync();
// Log cleanup happens here instead of ServiceBase or other objects because we want it to run only once before
// application exit, not per-service.
var logJanitor = _container.Resolve<ILogJanitor>();
logJanitor.DeleteOldestLogFiles(20);
return status; return status;
} }

Loading…
Cancel
Save