public static async Task <IDistributedLock> TryLockAsync(
            this IBlobStorage blobStorage,
            string container,
            string key,
            TimeSpan?lockDuration)
        {
            try
            {
                var leaseId = await blobStorage.AcquireLeaseAsync
                              (
                    container : container,
                    key : key,
                    leaseTime : lockDuration
                              );

                return(new BlobLeaseBasedLock
                       (
                           blobStorage: blobStorage,
                           container: container,
                           key: key,
                           leaseId: leaseId,
                           lockDuration: lockDuration
                       ));
            }
            catch (StorageException e) when(e.RequestInformation.HttpStatusCode == StatusCodes.Status409Conflict)
            {
                return(null);
            }
        }
示例#2
0
 public async Task <string> AcquireLeaseAsync(string container, string key, TimeSpan?leaseTime, string proposedLeaseId = null)
 => await WrapAsync(async() => await _impl.AcquireLeaseAsync(container, key, leaseTime, proposedLeaseId), container);
示例#3
0
 public async Task <string> AcquireLeaseAsync(string container, string key, TimeSpan?leaseTime, string proposedLeaseId = null)
 => await _retryService.RetryAsync(async() => await _impl.AcquireLeaseAsync(container, key, leaseTime, proposedLeaseId), _onModificationsRetryCount);