Class DistributedBackgroundService
Extends the BackgroundService adding a distributed lock mechanism to prevent concurrent executions.
Inheritance
Inherited Members
Namespace: Silverback.Background
Assembly: Silverback.Core.dll
Syntax
public abstract class DistributedBackgroundService : BackgroundService, IHostedService, IDisposable
Constructors
| Improve this doc View sourceDistributedBackgroundService(DistributedLockSettings?, IDistributedLockManager, ISilverbackLogger<DistributedBackgroundService>)
Initializes a new instance of the DistributedBackgroundService class.
Declaration
protected DistributedBackgroundService(DistributedLockSettings? distributedLockSettings, IDistributedLockManager distributedLockManager, ISilverbackLogger<DistributedBackgroundService> logger)
Parameters
Type | Name | Description |
---|---|---|
DistributedLockSettings | distributedLockSettings | Customizes the lock mechanism settings. |
IDistributedLockManager | distributedLockManager | |
ISilverbackLogger<DistributedBackgroundService> | logger | The ISilverbackLogger. |
DistributedBackgroundService(IDistributedLockManager, ISilverbackLogger<DistributedBackgroundService>)
Initializes a new instance of the DistributedBackgroundService class using the default settings for the lock mechanism.
Declaration
protected DistributedBackgroundService(IDistributedLockManager distributedLockManager, ISilverbackLogger<DistributedBackgroundService> logger)
Parameters
Type | Name | Description |
---|---|---|
IDistributedLockManager | distributedLockManager | |
ISilverbackLogger<DistributedBackgroundService> | logger | The ISilverbackLogger. |
Properties
| Improve this doc View sourceLock
Gets the acquired DistributedLock.
Declaration
protected DistributedLock? Lock { get; }
Property Value
Type | Description |
---|---|
DistributedLock |
Methods
| Improve this doc View sourceExecuteAsync(CancellationToken)
This method is called when the IHostedService starts. The implementation should return a task that represents the lifetime of the long running operation(s) being performed.
Declaration
protected override Task ExecuteAsync(CancellationToken stoppingToken)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | stoppingToken | Triggered when StopAsync(CancellationToken) is called. |
Returns
Type | Description |
---|---|
Task | A Task that represents the long running operations. |
Overrides
| Improve this doc View sourceExecuteLockedAsync(CancellationToken)
This method is called when the IHostedService starts and the lock is acquired. The implementation should return a task that represents the lifetime of the long running operation(s) being performed.
Declaration
protected abstract Task ExecuteLockedAsync(CancellationToken stoppingToken)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | stoppingToken | A CancellationToken to observe while waiting for the task to complete. |
Returns
Type | Description |
---|---|
Task | A Task that represents the long running operations. |