示例#1
0
        /// <summary>
        /// Tries to renew the lock lease.
        /// </summary>
        /// <param name="lockLease">The lock lease.</param>
        /// <returns>True if operation is successful, otherwise false.</returns>
        public static async Task <bool> TryRenewAsync(this ILockLease lockLease)
        {
            try {
                await lockLease.RenewAsync();

                return(true);
            } catch (Exception) {
                return(false);
            }
        }
示例#2
0
        /// <inheritdoc />
        public async Task ReleaseLock(ILockLease @lock)
        {
            var lockFileBlob  = BlobContainer.GetBlobClient($"locks/{@lock.Name}.lock");
            var lockFileLease = lockFileBlob.GetBlobLeaseClient(@lock.LeaseId);
            await lockFileLease.ReleaseAsync();

            // the following code that tries to delete had side-effects.
            // Not deleting is not problem whatsoever but
            // there are multiple zero byte files that are never deleted on storage.
            //try {
            //    var response = await lockFileBlob.DeleteIfExistsAsync();
            //} catch {; }
        }
示例#3
0
        /// <summary>
        /// Tries to renew the lock lease.
        /// </summary>
        /// <param name="lockLease">The lock lease.</param>
        /// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
        /// <param name="intervalInSeconds">Specifies the duration in seconds to wait for a renew attempt.</param>
        /// <returns>The task that represents the asynchronous operation result for renewing the lease.</returns>
        public static async Task TryRenewUntilCancelled(this ILockLease lockLease, CancellationToken cancellationToken, int intervalInSeconds = 10)
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                // Immediately try to renew the lease.
                var renewed = await lockLease.TryRenewAsync();

                if (!renewed)
                {
                    return;
                }
                // Wait for an amount of time before trying again to renew the lease.
                await Task.Delay(TimeSpan.FromSeconds(intervalInSeconds), cancellationToken);
            }
        }
示例#4
0
 /// <summary>
 /// Successful <see cref="LockLeaseResult"/> factory.
 /// </summary>
 /// <param name="lock">The lock</param>
 /// <returns></returns>
 public static LockLeaseResult Success(ILockLease @lock) => new LockLeaseResult(@lock, true);
示例#5
0
 private LockLeaseResult(ILockLease @lock, bool ok)
 {
     Lock = @lock;
     Ok   = ok;
 }
示例#6
0
 /// <inheritdoc />
 public async Task ReleaseLock(ILockLease @lock)
 {
     var lockFileBlob  = BlobContainer.GetBlobClient($"locks/{@lock.Name}.lock");
     var lockFileLease = lockFileBlob.GetBlobLeaseClient(@lock.LeaseId);
     await lockFileLease.ReleaseAsync();
 }
示例#7
0
 /// <inheritdoc/>
 public Task ReleaseLock(ILockLease @lock) => Task.CompletedTask;
示例#8
0
 /// <inheritdoc />
 public Task ReleaseLock(ILockLease @lock)
 {
     _signal.Release();
     _logger.LogInformation("Item with lease id {0} released the lock.", @lock.LeaseId);
     return(Task.CompletedTask);
 }
 /// <inheritdoc/>
 public async Task ReleaseLock(ILockLease @lock)
 {
     var query = @"DELETE FROM [work].[Lock] WHERE ([Name] = {0} AND [Id] < {1}) OR [ExpirationDate] < GetDate();";
     await _dbContext.Database.ExecuteSqlRawAsync(query, @lock.Name, Base64Id.Parse(@lock.LeaseId).Id);
 }
示例#10
0
 /// <inheritdoc/>
 public async Task ReleaseLock(ILockLease @lock) => await _dbContext.Database.ExecuteSqlRawAsync(_queryDescriptor.ReleaseLock, @lock.Name, Base64Id.Parse(@lock.LeaseId).Id);