diff --git a/framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/HangfireDynamicBackgroundWorkerManager.cs b/framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/HangfireDynamicBackgroundWorkerManager.cs index 53820d0522..040be6b3e5 100644 --- a/framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/HangfireDynamicBackgroundWorkerManager.cs +++ b/framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/HangfireDynamicBackgroundWorkerManager.cs @@ -140,29 +140,31 @@ public class HangfireDynamicBackgroundWorkerManager : IDynamicBackgroundWorkerMa protected virtual string GetCron(int period) { var time = TimeSpan.FromMilliseconds(period); - string cron; if (time.TotalSeconds <= 59) { - cron = $"*/{time.TotalSeconds} * * * * *"; + var seconds = (int)Math.Round(time.TotalSeconds); + return $"*/{seconds} * * * * *"; } - else if (time.TotalMinutes <= 59) - { - cron = $"*/{time.TotalMinutes} * * * *"; - } - else if (time.TotalHours <= 23) + + if (time.TotalMinutes <= 59) { - cron = $"0 */{time.TotalHours} * * *"; + var minutes = (int)Math.Round(time.TotalMinutes); + return $"*/{minutes} * * * *"; } - else if (time.TotalDays <= 31) + + if (time.TotalHours <= 23) { - cron = $"0 0 0 1/{time.TotalDays} * *"; + var hours = (int)Math.Round(time.TotalHours); + return $"0 */{hours} * * *"; } - else + + if (time.TotalDays <= 31) { - throw new AbpException($"Cannot convert period: {period} to cron expression."); + var days = (int)Math.Round(time.TotalDays); + return $"0 0 */{days} * *"; } - return cron; + throw new AbpException($"Cannot convert period: {period} to cron expression."); } } diff --git a/framework/src/Volo.Abp.BackgroundWorkers.TickerQ/Volo/Abp/BackgroundWorkers/TickerQ/TickerQDynamicBackgroundWorkerManager.cs b/framework/src/Volo.Abp.BackgroundWorkers.TickerQ/Volo/Abp/BackgroundWorkers/TickerQ/TickerQDynamicBackgroundWorkerManager.cs index efe8f3eebf..e5409b1b9a 100644 --- a/framework/src/Volo.Abp.BackgroundWorkers.TickerQ/Volo/Abp/BackgroundWorkers/TickerQ/TickerQDynamicBackgroundWorkerManager.cs +++ b/framework/src/Volo.Abp.BackgroundWorkers.TickerQ/Volo/Abp/BackgroundWorkers/TickerQ/TickerQDynamicBackgroundWorkerManager.cs @@ -92,6 +92,10 @@ public class TickerQDynamicBackgroundWorkerManager : IDynamicBackgroundWorkerMan AbpTickerQBackgroundWorkersProvider.BackgroundWorkers.Remove(functionName); HandlerRegistry.Unregister(workerName); + // Note: ICronTickerManager does not provide a remove API. + // The handler is unregistered above, so any persisted cron entry will + // find a null handler and skip execution silently. + return Task.FromResult(true); } @@ -138,6 +142,9 @@ public class TickerQDynamicBackgroundWorkerManager : IDynamicBackgroundWorkerMan var time = TimeSpan.FromMilliseconds(period); if (time.TotalMinutes < 1) { + Logger.LogWarning( + "TickerQ does not support sub-minute intervals. Period {Period}ms will be rounded up to every minute.", + period); return "* * * * *"; } diff --git a/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/DefaultDynamicBackgroundWorkerManager.cs b/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/DefaultDynamicBackgroundWorkerManager.cs index 3d239215dc..030b6299d0 100644 --- a/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/DefaultDynamicBackgroundWorkerManager.cs +++ b/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/DefaultDynamicBackgroundWorkerManager.cs @@ -37,7 +37,7 @@ public class DefaultDynamicBackgroundWorkerManager : IDynamicBackgroundWorkerMan schedule.Validate(); - if (schedule.Period == null && !string.IsNullOrWhiteSpace(schedule.CronExpression)) + if (schedule.Period == null) { throw new AbpException( $"The default in-memory background worker manager does not support CronExpression without Period for dynamic worker '{workerName}'. " + @@ -79,7 +79,7 @@ public class DefaultDynamicBackgroundWorkerManager : IDynamicBackgroundWorkerMan schedule.Validate(); - if (schedule.Period == null && !string.IsNullOrWhiteSpace(schedule.CronExpression)) + if (schedule.Period == null) { throw new AbpException( $"The default in-memory background worker manager does not support CronExpression without Period for dynamic worker '{workerName}'. " +