Browse Source
Merge pull request #21641 from abpframework/backgroundworker
Allow to customize the distributed lock key of BackgroundJobWorker
pull/21660/head
liangshiwei
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
15 additions and
3 deletions
-
docs/en/framework/infrastructure/background-jobs/index.md
-
framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/AbpBackgroundJobWorkerOptions.cs
-
framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobWorker.cs
|
|
|
@ -221,6 +221,13 @@ public class MyModule : AbpModule |
|
|
|
} |
|
|
|
```` |
|
|
|
|
|
|
|
* `JobPollPeriod` is used to determine the interval between two job polling operations. Default is 5000 ms (5 seconds). |
|
|
|
* `MaxJobFetchCount` is used to determine the maximum job count to fetch in a single polling operation. Default is 1000. |
|
|
|
* `DefaultFirstWaitDuration` is used to determine the duration to wait before the first retry. Default is 60 seconds. |
|
|
|
* `DefaultTimeout` is used to determine the timeout duration for a job. Default is 172800 seconds (2 days). |
|
|
|
* `DefaultWaitFactor` is used to determine the factor to increase the wait duration between retries. Default is 2.0. |
|
|
|
* `DistributedLockName` is used to determine the distributed lock name to use. Default is `AbpBackgroundJobWorker`. |
|
|
|
|
|
|
|
### Data Store |
|
|
|
|
|
|
|
The default background job manager needs a data store to save and read jobs. It defines `IBackgroundJobStore` as an abstraction to store the jobs. |
|
|
|
|
|
|
|
@ -33,6 +33,12 @@ public class AbpBackgroundJobWorkerOptions |
|
|
|
/// </summary>
|
|
|
|
public double DefaultWaitFactor { get; set; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Distributed lock name for the worker.
|
|
|
|
/// Default value: "AbpBackgroundJobWorker".
|
|
|
|
/// </summary>
|
|
|
|
public string DistributedLockName { get; set; } |
|
|
|
|
|
|
|
public AbpBackgroundJobWorkerOptions() |
|
|
|
{ |
|
|
|
MaxJobFetchCount = 1000; |
|
|
|
@ -40,5 +46,6 @@ public class AbpBackgroundJobWorkerOptions |
|
|
|
DefaultFirstWaitDuration = 60; |
|
|
|
DefaultTimeout = 172800; |
|
|
|
DefaultWaitFactor = 2.0; |
|
|
|
DistributedLockName = "AbpBackgroundJobWorker"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -13,8 +13,6 @@ namespace Volo.Abp.BackgroundJobs; |
|
|
|
|
|
|
|
public class BackgroundJobWorker : AsyncPeriodicBackgroundWorkerBase, IBackgroundJobWorker |
|
|
|
{ |
|
|
|
protected const string DistributedLockName = "AbpBackgroundJobWorker"; |
|
|
|
|
|
|
|
protected AbpBackgroundJobOptions JobOptions { get; } |
|
|
|
|
|
|
|
protected AbpBackgroundJobWorkerOptions WorkerOptions { get; } |
|
|
|
@ -39,7 +37,7 @@ public class BackgroundJobWorker : AsyncPeriodicBackgroundWorkerBase, IBackgroun |
|
|
|
|
|
|
|
protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext) |
|
|
|
{ |
|
|
|
await using (var handler = await DistributedLock.TryAcquireAsync(DistributedLockName, cancellationToken: StoppingToken)) |
|
|
|
await using (var handler = await DistributedLock.TryAcquireAsync(WorkerOptions.DistributedLockName, cancellationToken: StoppingToken)) |
|
|
|
{ |
|
|
|
if (handler != null) |
|
|
|
{ |
|
|
|
|