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

This commit is contained in:
Joseph Milazzo 2021-03-15 17:10:09 -05:00
parent fad4ca4414
commit 55cd0c5fe5

View File

@ -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;
@ -40,7 +42,17 @@ namespace API.Services
_cleanupService = cleanupService;
_directoryService = directoryService;
ScheduleTasks();
if (!env.IsDevelopment())
{
ScheduleTasks();
}
else
{
RecurringJob.RemoveIfExists("scan-libraries");
RecurringJob.RemoveIfExists("backup");
RecurringJob.RemoveIfExists("cleanup");
}
}
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)