public async Task ReleaseAsync(DistributedLockSettings settings) { Check.NotNull(settings, nameof(settings)); if (settings is NullLockSettings) { await NullLockManager.ReleaseAsync(settings).ConfigureAwait(false); } var tryCount = 1; while (tryCount <= 3) { try { using var scope = _serviceScopeFactory.CreateScope(); await ReleaseAsync(settings.ResourceName, settings.UniqueId, scope.ServiceProvider) .ConfigureAwait(false); _logger.LogLockReleased(settings); break; } catch (Exception ex) { _logger.LogFailedToReleaseLock(settings, ex); tryCount++; } } }
public async Task ReleaseAsync(DistributedLockSettings settings) { Check.NotNull(settings, nameof(settings)); if (settings is NullLockSettings) { await NullLockManager.ReleaseAsync(settings).ConfigureAwait(false); } var tryCount = 1; while (tryCount <= 3) { try { using var scope = _serviceScopeFactory.CreateScope(); await ReleaseAsync(settings.ResourceName, settings.UniqueId, scope.ServiceProvider) .ConfigureAwait(false); _logger.LogInformation( CoreEventIds.DistributedLockReleased, "Released lock {lockName} ({lockUniqueId}).", settings.ResourceName, settings.UniqueId); break; } catch (Exception ex) { _logger.LogWarning( CoreEventIds.FailedToReleaseDistributedLock, ex, "Failed to release lock '{lockName} ({lockUniqueId})'. See inner exception for details.", settings.ResourceName, settings.UniqueId); tryCount++; } } }
/// <summary> /// Releases the lock. /// </summary> /// <returns> /// A <see cref="Task" /> representing the asynchronous operation. /// </returns> public async Task ReleaseAsync() { Status = DistributedLockStatus.Released; await _lockManager.ReleaseAsync(_settings).ConfigureAwait(false); }