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
parent
commit
2f1cead35c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 7
      docs/en/framework/infrastructure/background-jobs/index.md
  2. 7
      framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/AbpBackgroundJobWorkerOptions.cs
  3. 4
      framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobWorker.cs

7
docs/en/framework/infrastructure/background-jobs/index.md

@ -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.

7
framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/AbpBackgroundJobWorkerOptions.cs

@ -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";
}
}

4
framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobWorker.cs

@ -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)
{

Loading…
Cancel
Save