From 5d0a48e7cdee3319d18a143b9f54bcadf27595e5 Mon Sep 17 00:00:00 2001 From: Flaminel Date: Sun, 1 Jun 2025 18:49:59 +0300 Subject: [PATCH] fixed download cleaner job on api update --- .../Controllers/ConfigurationController.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/code/Executable/Controllers/ConfigurationController.cs b/code/Executable/Controllers/ConfigurationController.cs index f7519797..a686e10b 100644 --- a/code/Executable/Controllers/ConfigurationController.cs +++ b/code/Executable/Controllers/ConfigurationController.cs @@ -169,6 +169,28 @@ public class ConfigurationController : ControllerBase await _jobManagementService.StopJob(JobType.QueueCleaner); } } + + /// + /// Updates the DownloadCleaner job schedule based on configuration changes + /// + /// The DownloadCleaner configuration + private async Task UpdateDownloadCleanerJobSchedule(DownloadCleanerConfig config) + { + if (config.Enabled) + { + // If the job is enabled, update its schedule with the configured cron expression + _logger.LogInformation("DownloadCleaner is enabled, updating job schedule with cron expression: {CronExpression}", config.CronExpression); + + // Create a Quartz job schedule with the cron expression + await _jobManagementService.StartJob(JobType.DownloadCleaner, null, config.CronExpression); + } + else + { + // If the job is disabled, stop it + _logger.LogInformation("DownloadCleaner is disabled, stopping the job"); + await _jobManagementService.StopJob(JobType.DownloadCleaner); + } + } [HttpPut("content_blocker")] public async Task UpdateContentBlockerConfig([FromBody] ContentBlockerConfigUpdateDto dto) @@ -211,6 +233,9 @@ public class ConfigurationController : ControllerBase return StatusCode(500, "Failed to save DownloadCleaner configuration"); } + // Update the scheduler based on configuration changes + await UpdateDownloadCleanerJobSchedule(config); + return Ok(new { Message = "DownloadCleaner configuration updated successfully" }); }