Skip to content

Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.

For the time out on tasks, I'm going to only use Hangfire scheduled tasks on prod.

Joseph Milazzo55cd0c5fe54e
diff --git a/API/Services/TaskScheduler.cs b/API/Services/TaskScheduler.cs
index 70bca9121..28241aaea 100644
--- a/API/Services/TaskScheduler.cs
+++ b/API/Services/TaskScheduler.cs
@@ -6,6 +6,8 @@ using API.Helpers.Converters;
using API.Interfaces;
using API.Interfaces.Services;
using Hangfire;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace API.Services
@@ -29,7 +31,7 @@ namespace API.Services
public TaskScheduler(ICacheService cacheService, ILogger<TaskScheduler> logger, IScannerService scannerService,
IUnitOfWork unitOfWork, IMetadataService metadataService, IBackupService backupService, ICleanupService cleanupService,
- IDirectoryService directoryService)
+ IDirectoryService directoryService, IWebHostEnvironment env)
{
_cacheService = cacheService;
_logger = logger;
@@ -39,8 +41,18 @@ namespace API.Services
_backupService = backupService;
_cleanupService = cleanupService;
_directoryService = directoryService;
+
+ if (!env.IsDevelopment())
+ {
+ ScheduleTasks();
+ }
+ else
+ {
+ RecurringJob.RemoveIfExists("scan-libraries");
+ RecurringJob.RemoveIfExists("backup");
+ RecurringJob.RemoveIfExists("cleanup");
+ }
- ScheduleTasks();
}
public void ScheduleTasks()
@@ -78,8 +90,7 @@ namespace API.Services
_logger.LogInformation("Enqueuing library scan for: {LibraryId}", libraryId);
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
- RecurringJob.Trigger("cleanup"); // TODO: Alternate way to trigger jobs. Test this out and see if we should switch.
+ BackgroundJob.Enqueue(() => _cleanupService.Cleanup()); // When we do a scan, force cache to re-unpack in case page numbers change
}
public void CleanupChapters(int[] chapterIds)