private async Task ProcessBlobAsync(Uri blobUri, CancellationToken token) { _logger.LogInformation("ProcessBlobAsync: Start to process blob to {BlobName}.", blobUri.AbsoluteUri); if (token.IsCancellationRequested) { _logger.LogInformation("ProcessBlobAsync: The operation was cancelled."); return; } using (var lockResult = await _source.TakeLockAsync(blobUri, token)) { if (lockResult.LockIsTaken /*lockResult*/) { var operationToken = lockResult.BlobOperationToken.Token; if (!operationToken.IsCancellationRequested) { using (var inputStream = await _source.OpenReadAsync(blobUri, ContentType.GZip, token)) { var writeOperationResult = await _destination.TryWriteAsync(inputStream, ProcessStream, blobUri.Segments.Last(), ContentType.GZip, operationToken); await _source.TryCleanAsync(lockResult, onError : writeOperationResult.OperationException != null, token : operationToken); await _source.TryReleaseLockAsync(lockResult, operationToken); } } } } _logger.LogInformation("ProcessBlobAsync: Finished to process blob {BlobName}", blobUri.AbsoluteUri); }
private async Task TryProcessBlobAsync(Uri file, Func <string, string> fileNameTransform, ContentType sourceContentType, ContentType destinationContentType, ConcurrentBag <Exception> exceptions, CancellationToken token) { _logger.LogInformation("TryProcessAsync: {File} ", file.AbsoluteUri); if (token.IsCancellationRequested) { _logger.LogInformation("TryProcessAsync: The operation was cancelled."); } try { using (var lockResult = _source.TakeLockAsync(file, token).Result) { var blobOperationToken = lockResult.BlobOperationToken.Token; if (lockResult.LockIsTaken /*lockResult*/) { using (var inputStream = await _source.OpenReadAsync(file, sourceContentType, blobOperationToken)) { var blobToDeadLetter = !await VerifyStreamInternalAsync(file, sourceContentType, blobOperationToken); // If verification passed continue with the rest of the action // If not just move the blob to deadletter if (!blobToDeadLetter) { var writeOperationResult = await _destination.TryWriteAsync(inputStream, ProcessLogStream, fileNameTransform(file.Segments.Last()), destinationContentType, blobOperationToken); blobToDeadLetter = writeOperationResult.OperationException != null; } await _source.TryCleanAsync(lockResult, onError : blobToDeadLetter, token : blobOperationToken); await _source.TryReleaseLockAsync(lockResult, token : blobOperationToken); } } } } catch (Exception exception) { // Add any exceptions AddException(exceptions, exception); } }