Class DbDistributedLockManager
Implements a lock mechanism that relies on a shared database table to synchronize different processes.
Implements
Inherited Members
Namespace: Silverback.Background
Assembly: Silverback.Core.dll
Syntax
public class DbDistributedLockManager : IDistributedLockManager
Constructors
| Improve this doc View sourceDbDistributedLockManager(IServiceScopeFactory, ISilverbackLogger<DbDistributedLockManager>)
Initializes a new instance of the DbDistributedLockManager class.
Declaration
public DbDistributedLockManager(IServiceScopeFactory serviceScopeFactory, ISilverbackLogger<DbDistributedLockManager> logger)
Parameters
Type | Name | Description |
---|---|---|
IServiceScopeFactory | serviceScopeFactory | The IServiceScopeFactory used to resolve the scoped types. |
ISilverbackLogger<DbDistributedLockManager> | logger | The ISilverbackLogger. |
Methods
| Improve this doc View sourceAcquireAsync(DistributedLockSettings, CancellationToken)
Acquires a new lock on the specified resource.
Declaration
public Task<DistributedLock?> AcquireAsync(DistributedLockSettings settings, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
DistributedLockSettings | settings | Specifies all settings of the lock to be acquired. |
CancellationToken | cancellationToken | A CancellationToken to observe while waiting for the task to complete. |
Returns
Type | Description |
---|---|
Task<DistributedLock> | A Task<TResult> representing the asynchronous operation. The task result contains the
acquired DistributedLock (or |
CheckIsStillLockedAsync(DistributedLockSettings)
Returns a boolean value indicating whether the specified lock is taken already.
Declaration
public Task<bool> CheckIsStillLockedAsync(DistributedLockSettings settings)
Parameters
Type | Name | Description |
---|---|---|
DistributedLockSettings | settings | Specifies the lock to be checked. |
Returns
Type | Description |
---|---|
Task<bool> | A Task<TResult> representing the asynchronous operation. The task result contains a boolean value indicating whether the lock is taken. |
ReleaseAsync(DistributedLockSettings)
Releases the lock.
Declaration
public Task ReleaseAsync(DistributedLockSettings settings)
Parameters
Type | Name | Description |
---|---|---|
DistributedLockSettings | settings | Specifies the lock to be released. |
Returns
Type | Description |
---|---|
Task | A Task representing the asynchronous operation. |
SendHeartbeatAsync(DistributedLockSettings)
Called periodically after the lock has been acquired to send an heartbeat that keeps the lock.
Declaration
public Task<bool> SendHeartbeatAsync(DistributedLockSettings settings)
Parameters
Type | Name | Description |
---|---|---|
DistributedLockSettings | settings | Specifies the lock to be refreshed. |
Returns
Type | Description |
---|---|
Task<bool> | A Task<TResult> representing the asynchronous operation. The task result contains a boolean value indicating whether the lock could be refreshed. |