Browse Source
Improve error messages for CronExpression in DefaultDynamicBackgroundWorkerManager and add test for exception on UpdateSchedule with CronExpression
pull/25397/head
maliming
4 months ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
3 changed files with
32 additions and
2 deletions
-
framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/DefaultDynamicBackgroundWorkerManager.cs
-
framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/IDynamicBackgroundWorkerManager.cs
-
framework/test/Volo.Abp.BackgroundJobs.Tests/Volo/Abp/BackgroundWorkers/DynamicBackgroundWorkerManager_Tests.cs
|
|
|
@ -46,7 +46,7 @@ public class DefaultDynamicBackgroundWorkerManager : |
|
|
|
{ |
|
|
|
throw new AbpException( |
|
|
|
$"The default in-memory background worker manager does not support CronExpression for dynamic worker '{workerName}'. " + |
|
|
|
"Please set Period, or use a scheduler-backed provider (Hangfire or Quartz)."); |
|
|
|
"Please clear CronExpression and use Period-based scheduling, or use a scheduler-backed provider (Hangfire or Quartz)."); |
|
|
|
} |
|
|
|
|
|
|
|
await _semaphore.WaitAsync(cancellationToken); |
|
|
|
@ -109,7 +109,7 @@ public class DefaultDynamicBackgroundWorkerManager : |
|
|
|
{ |
|
|
|
throw new AbpException( |
|
|
|
$"The default in-memory background worker manager does not support CronExpression for dynamic worker '{workerName}'. " + |
|
|
|
"Please set Period, or use a scheduler-backed provider (Hangfire or Quartz)."); |
|
|
|
"Please clear CronExpression and use Period-based scheduling, or use a scheduler-backed provider (Hangfire or Quartz)."); |
|
|
|
} |
|
|
|
|
|
|
|
await _semaphore.WaitAsync(cancellationToken); |
|
|
|
|
|
|
|
@ -6,6 +6,12 @@ namespace Volo.Abp.BackgroundWorkers; |
|
|
|
/// <summary>
|
|
|
|
/// Manages dynamic background workers that are registered at runtime
|
|
|
|
/// without requiring a strongly-typed worker class.
|
|
|
|
/// <para>
|
|
|
|
/// Implementations may differ in capabilities. Check <see cref="ISupportsRuntimeRegistration"/>
|
|
|
|
/// before calling <see cref="AddAsync"/> / <see cref="RemoveAsync"/> / <see cref="UpdateScheduleAsync"/>,
|
|
|
|
/// and <see cref="ISupportsCronScheduling"/> before passing
|
|
|
|
/// <see cref="DynamicBackgroundWorkerSchedule.CronExpression"/>.
|
|
|
|
/// </para>
|
|
|
|
/// </summary>
|
|
|
|
public interface IDynamicBackgroundWorkerManager |
|
|
|
{ |
|
|
|
|
|
|
|
@ -262,6 +262,30 @@ public class DynamicBackgroundWorkerManager_Tests : BackgroundJobsTestBase |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Should_Throw_When_CronExpression_Is_Set_On_UpdateSchedule() |
|
|
|
{ |
|
|
|
var workerName = "dynamic-worker-" + Guid.NewGuid(); |
|
|
|
|
|
|
|
await _dynamicWorkerManager.AddAsync( |
|
|
|
workerName, |
|
|
|
new DynamicBackgroundWorkerSchedule { Period = 1000 }, |
|
|
|
(_, _) => Task.CompletedTask |
|
|
|
); |
|
|
|
|
|
|
|
await Assert.ThrowsAsync<AbpException>(async () => |
|
|
|
{ |
|
|
|
await _dynamicWorkerManager.UpdateScheduleAsync( |
|
|
|
workerName, |
|
|
|
new DynamicBackgroundWorkerSchedule |
|
|
|
{ |
|
|
|
Period = 1000, |
|
|
|
CronExpression = "0 */5 * * * *" |
|
|
|
} |
|
|
|
); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Should_Continue_Running_After_Handler_Throws_Exception() |
|
|
|
{ |
|
|
|
|