public async Task <bool> IsLockedAsync(string assetId) { var partitionKey = CashoutLockEntity.GetPartitionKey(assetId); var rowKey = CashoutLockEntity.GetRowKey(assetId); return(await _storage.GetDataAsync(partitionKey, rowKey) != null); }
public async Task <bool> ReleaseLockAsync(string assetId, Guid operationId) { var partitionKey = CashoutLockEntity.GetPartitionKey(assetId); var rowKey = CashoutLockEntity.GetRowKey(assetId); return(await _storage.DeleteIfExistAsync( partitionKey, rowKey, // Exactly the given transaction should own current lock to remove it lockEntity => lockEntity.OperationId == operationId)); }
public async Task <(DateTime lockedAt, Guid operationId)?> GetLockAsync(string assetId) { var partitionKey = CashoutLockEntity.GetPartitionKey(assetId); var rowKey = CashoutLockEntity.GetRowKey(assetId); var lockEntity = await _storage.GetDataAsync(partitionKey, rowKey); if (lockEntity != null) { return(lockEntity.LockedAt, lockEntity.OperationId); } return(null); }
public async Task <bool> TryLockAsync(string assetId, Guid operationId, DateTime lockedAt) { var partitionKey = CashoutLockEntity.GetPartitionKey(assetId); var rowKey = CashoutLockEntity.GetRowKey(assetId); var lockEntity = await _storage.GetOrInsertAsync(partitionKey, rowKey, () => new CashoutLockEntity { PartitionKey = partitionKey, RowKey = rowKey, OperationId = operationId, AssetId = assetId, LockedAt = lockedAt }); return(lockEntity?.OperationId == operationId); }