public async Task <string> AcquireLeaseAsync(CancellationToken token) { var blobNotFound = false; try { return(await leaseBlob.AcquireLeaseAsync(TimeSpan.FromSeconds(60))); } catch (StorageException storageException) { var errorCode = storageException.RequestInformation.ExtendedErrorInformation.ErrorCode; if (errorCode.Equals("ContainerNotFound", StringComparison.OrdinalIgnoreCase) || errorCode.Equals("BlobNotFound", StringComparison.OrdinalIgnoreCase)) { blobNotFound = true; } else if (errorCode.Equals("LeaseAlreadyPresent", StringComparison.OrdinalIgnoreCase)) { return(null); } else { logger.LogError($"Error acquiring lease. Details: {storageException}"); } } if (blobNotFound) { await CreateBlobAsync(token); return(await AcquireLeaseAsync(token)); } return(null); }
public async Task <bool> AcquireLease(LeaseOptions options, CancellationToken token) { var leaseIdentifier = NodeToLeaseIdentifier(options.NodeId); try { var lease = await leaseBlob.AcquireLeaseAsync(leaseLength, leaseIdentifier, token); logger.Info($"Lease aquired, lease length {leaseLength}."); return(leaseIdentifier == lease); } catch (StorageException storageException) { if (storageException.InnerException is WebException webException && webException.Response is HttpWebResponse response) { switch (response.StatusCode) { case HttpStatusCode.NotFound: await CreateBlobAsync(token); return(await AcquireLease(options, token)); case HttpStatusCode.Conflict: logger.Info("Could not Aquire the lease, another node owns the lease."); return(false); } } throw; } }
public async Task <string> AcquireLeaseAsync(CancellationToken token) { bool blobNotFound = false; try { return(await _leaseBlob.AcquireLeaseAsync(Constants.AcquireLeaseFor, null, token)); } catch (StorageException storageException) { var webException = storageException.InnerException as WebException; if (webException != null) { var response = webException.Response as HttpWebResponse; if (response != null) { if (response.StatusCode == HttpStatusCode.NotFound) { blobNotFound = true; } if (response.StatusCode == HttpStatusCode.Conflict) { return(null); } } else { return(null); } } } if (blobNotFound) { await CreateBlobAsync(token); return(await AcquireLeaseAsync(token)); } return(null); }
/// <inheritdoc /> public Task <string> AcquireLeaseAsync(TimeSpan?leaseTime, string proposedLeaseId, CancellationToken cancellationToken) { return(_sdk.AcquireLeaseAsync(leaseTime, proposedLeaseId, accessCondition: null, options: null, operationContext: null, cancellationToken: cancellationToken)); }
/// <inheritdoc /> public Task <string> AcquireLeaseAsync(TimeSpan?leaseTime, string proposedLeaseId, CancellationToken cancellationToken) { return(_sdk.AcquireLeaseAsync(leaseTime, proposedLeaseId, cancellationToken)); }