mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-02 21:24:18 -04:00
37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
using System.IO;
|
|
using API.Interfaces.Services;
|
|
using Hangfire;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace API.Services.Tasks
|
|
{
|
|
/// <summary>
|
|
/// Cleans up after operations on reoccurring basis
|
|
/// </summary>
|
|
public class CleanupService : ICleanupService
|
|
{
|
|
private readonly ICacheService _cacheService;
|
|
private readonly ILogger<CleanupService> _logger;
|
|
private readonly IBackupService _backupService;
|
|
|
|
public CleanupService(ICacheService cacheService, ILogger<CleanupService> logger, IBackupService backupService)
|
|
{
|
|
_cacheService = cacheService;
|
|
_logger = logger;
|
|
_backupService = backupService;
|
|
}
|
|
|
|
[AutomaticRetry(Attempts = 3, LogEvents = false, OnAttemptsExceeded = AttemptsExceededAction.Fail)]
|
|
public void Cleanup()
|
|
{
|
|
_logger.LogInformation("Cleaning temp directory");
|
|
var tempDirectory = Path.Join(Directory.GetCurrentDirectory(), "temp");
|
|
DirectoryService.ClearDirectory(tempDirectory);
|
|
_logger.LogInformation("Cleaning cache directory");
|
|
_cacheService.Cleanup();
|
|
_logger.LogInformation("Cleaning old database backups");
|
|
_backupService.CleanupBackups();
|
|
|
|
}
|
|
}
|
|
} |