mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-07-09 03:04:19 -04:00
Merge pull request #85 from Kareadita/feature/streams
Added a new method for triggering jobs rather than scheduling ad-hoc.
This commit is contained in:
commit
957f1fcd7f
8
.github/workflows/build.yml
vendored
8
.github/workflows/build.yml
vendored
@ -10,7 +10,7 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
name: Build
|
name: Build
|
||||||
runs-on: ubuntu-latest
|
runs-on: windows-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
@ -25,9 +25,9 @@ jobs:
|
|||||||
uses: actions/setup-java@v1
|
uses: actions/setup-java@v1
|
||||||
with:
|
with:
|
||||||
java-version: 1.11
|
java-version: 1.11
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
||||||
- name: Cache SonarCloud packages
|
- name: Cache SonarCloud packages
|
||||||
uses: actions/cache@v1
|
uses: actions/cache@v1
|
||||||
with:
|
with:
|
||||||
|
@ -1,4 +1,13 @@
|
|||||||
using Xunit;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using API.Data;
|
||||||
|
using API.Entities;
|
||||||
|
using API.Interfaces;
|
||||||
|
using API.Interfaces.Services;
|
||||||
|
using API.Services;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NSubstitute;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
namespace API.Tests.Services
|
namespace API.Tests.Services
|
||||||
{
|
{
|
||||||
@ -9,10 +18,33 @@ namespace API.Tests.Services
|
|||||||
// private readonly IUnitOfWork _unitOfWork = Substitute.For<IUnitOfWork>();
|
// private readonly IUnitOfWork _unitOfWork = Substitute.For<IUnitOfWork>();
|
||||||
// private readonly IArchiveService _archiveService = Substitute.For<IArchiveService>();
|
// private readonly IArchiveService _archiveService = Substitute.For<IArchiveService>();
|
||||||
// private readonly IDirectoryService _directoryService = Substitute.For<DirectoryService>();
|
// private readonly IDirectoryService _directoryService = Substitute.For<DirectoryService>();
|
||||||
|
//
|
||||||
// public CacheServiceTests()
|
// public CacheServiceTests()
|
||||||
// {
|
// {
|
||||||
// //_cacheService = new CacheService(_logger, _unitOfWork, _archiveService, _directoryService);
|
// _cacheService = new CacheService(_logger, _unitOfWork, _archiveService, _directoryService);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async void Ensure_ShouldExtractArchive(int chapterId)
|
||||||
|
// {
|
||||||
|
//
|
||||||
|
// // CacheDirectory needs to be customized.
|
||||||
|
// _unitOfWork.VolumeRepository.GetChapterAsync(chapterId).Returns(new Chapter
|
||||||
|
// {
|
||||||
|
// Id = 1,
|
||||||
|
// Files = new List<MangaFile>()
|
||||||
|
// {
|
||||||
|
// new MangaFile()
|
||||||
|
// {
|
||||||
|
// FilePath = ""
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// await _cacheService.Ensure(1);
|
||||||
|
//
|
||||||
|
// var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/CacheService/Archives");
|
||||||
|
//
|
||||||
// }
|
// }
|
||||||
|
|
||||||
//string GetCachedPagePath(Volume volume, int page)
|
//string GetCachedPagePath(Volume volume, int page)
|
||||||
@ -50,7 +82,7 @@ namespace API.Tests.Services
|
|||||||
// cacheService.Configure().GetVolumeCachePath(1, volume.Files.ElementAt(0)).Returns("cache/1/");
|
// cacheService.Configure().GetVolumeCachePath(1, volume.Files.ElementAt(0)).Returns("cache/1/");
|
||||||
// _directoryService.Configure().GetFilesWithExtension("cache/1/").Returns(new string[] {"pexels-photo-6551949.jpg"});
|
// _directoryService.Configure().GetFilesWithExtension("cache/1/").Returns(new string[] {"pexels-photo-6551949.jpg"});
|
||||||
// Assert.Equal(expected, _cacheService.GetCachedPagePath(volume, pageNum));
|
// Assert.Equal(expected, _cacheService.GetCachedPagePath(volume, pageNum));
|
||||||
Assert.True(true);
|
//Assert.True(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
Binary file not shown.
@ -1,4 +1,5 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using API.Entities.Enums;
|
using API.Entities.Enums;
|
||||||
using API.Helpers.Converters;
|
using API.Helpers.Converters;
|
||||||
@ -53,33 +54,34 @@ namespace API.Services
|
|||||||
if (setting != null)
|
if (setting != null)
|
||||||
{
|
{
|
||||||
_logger.LogDebug("Scheduling Scan Library Task for {Cron}", setting);
|
_logger.LogDebug("Scheduling Scan Library Task for {Cron}", setting);
|
||||||
RecurringJob.AddOrUpdate(() => _scannerService.ScanLibraries(), () => CronConverter.ConvertToCronNotation(setting));
|
RecurringJob.AddOrUpdate("scan-libraries", () => _scannerService.ScanLibraries(), () => CronConverter.ConvertToCronNotation(setting));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RecurringJob.AddOrUpdate(() => _scannerService.ScanLibraries(), Cron.Daily);
|
RecurringJob.AddOrUpdate("scan-libraries", () => _scannerService.ScanLibraries(), Cron.Daily);
|
||||||
}
|
}
|
||||||
|
|
||||||
setting = Task.Run(() => _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.TaskBackup)).Result.Value;
|
setting = Task.Run(() => _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.TaskBackup)).Result.Value;
|
||||||
if (setting != null)
|
if (setting != null)
|
||||||
{
|
{
|
||||||
_logger.LogDebug("Scheduling Backup Task for {Cron}", setting);
|
_logger.LogDebug("Scheduling Backup Task for {Cron}", setting);
|
||||||
RecurringJob.AddOrUpdate(() => _backupService.BackupDatabase(), () => CronConverter.ConvertToCronNotation(setting));
|
RecurringJob.AddOrUpdate("backup", () => _backupService.BackupDatabase(), () => CronConverter.ConvertToCronNotation(setting));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RecurringJob.AddOrUpdate(() => _backupService.BackupDatabase(), Cron.Weekly);
|
RecurringJob.AddOrUpdate("backup", () => _backupService.BackupDatabase(), Cron.Weekly);
|
||||||
}
|
}
|
||||||
|
|
||||||
RecurringJob.AddOrUpdate(() => _cleanupService.Cleanup(), Cron.Daily);
|
RecurringJob.AddOrUpdate("cleanup", () => _cleanupService.Cleanup(), Cron.Daily);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ScanLibrary(int libraryId, bool forceUpdate = false)
|
public void ScanLibrary(int libraryId, bool forceUpdate = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
_logger.LogInformation("Enqueuing library scan for: {LibraryId}", libraryId);
|
_logger.LogInformation("Enqueuing library scan for: {LibraryId}", libraryId);
|
||||||
BackgroundJob.Enqueue(() => _scannerService.ScanLibrary(libraryId, forceUpdate));
|
BackgroundJob.Enqueue(() => _scannerService.ScanLibrary(libraryId, forceUpdate));
|
||||||
BackgroundJob.Enqueue(() => _cleanupService.Cleanup()); // When we do a scan, force cache to re-unpack in case page numbers change
|
//BackgroundJob.Enqueue(() => _cleanupService.Cleanup()); // When we do a scan, force cache to re-unpack in case page numbers change
|
||||||
|
RecurringJob.Trigger("cleanup"); // TODO: Alternate way to trigger jobs. Test this out and see if we should switch.
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CleanupChapters(int[] chapterIds)
|
public void CleanupChapters(int[] chapterIds)
|
||||||
|
@ -63,7 +63,8 @@ namespace API.Services.Tasks
|
|||||||
_scannedSeries = null;
|
_scannedSeries = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//[DisableConcurrentExecution(timeoutInSeconds: 360)]
|
[DisableConcurrentExecution(5)]
|
||||||
|
[AutomaticRetry(Attempts = 0, LogEvents = false, OnAttemptsExceeded = AttemptsExceededAction.Delete)]
|
||||||
public void ScanLibrary(int libraryId, bool forceUpdate)
|
public void ScanLibrary(int libraryId, bool forceUpdate)
|
||||||
{
|
{
|
||||||
_forceUpdate = forceUpdate;
|
_forceUpdate = forceUpdate;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user