Class DistributedBackgroundService
- Namespace
- Silverback.Background
- Assembly
- Silverback.Core.dll
Extends the BackgroundService adding a distributed lock mechanism to prevent concurrent executions.
public abstract class DistributedBackgroundService : BackgroundService, IHostedService, IDisposable
- Inheritance
-
DistributedBackgroundService
- Implements
- Derived
- Inherited Members
Constructors
DistributedBackgroundService(IDistributedLock, ISilverbackLogger<DistributedBackgroundService>)
Initializes a new instance of the DistributedBackgroundService class.
protected DistributedBackgroundService(IDistributedLock distributedLock, ISilverbackLogger<DistributedBackgroundService> logger)
Parameters
distributedLockIDistributedLockThe IDistributedLock.
loggerISilverbackLogger<DistributedBackgroundService>The ISilverbackLogger.
Properties
DistributedLock
Gets the IDistributedLock used by this service.
protected IDistributedLock DistributedLock { get; }
Property Value
Methods
AcquireLockAndExecuteAsync(CancellationToken)
Acquires the lock and calls the ExecuteLockedAsync(CancellationToken) method to perform the operation(s).
protected virtual Task AcquireLockAndExecuteAsync(CancellationToken stoppingToken)
Parameters
stoppingTokenCancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
ExecuteAsync(CancellationToken)
protected override sealed Task ExecuteAsync(CancellationToken stoppingToken)
Parameters
stoppingTokenCancellationToken
Returns
ExecuteLockedAsync(CancellationToken)
This method is called after the lock is acquired to perform the actual operation(s). The implementation should return a task that represents the lifetime of the operation(s) being performed.
protected abstract Task ExecuteLockedAsync(CancellationToken stoppingToken)
Parameters
stoppingTokenCancellationTokenA CancellationToken to observe while waiting for the task to complete.