private async Task Run(IStreamHandler handler, IOptions <BlobStorageOptions> options, BlobItem item, CancellationToken stoppingToken) { try { _logger.LogInformation(item.Name); var leaseId = await _blobStorage.LeaseBlobAsync(options.Value.ContainerName, item, stoppingToken).ConfigureAwait(false); var blob = _blobStorage.GetBlobClient(options.Value.ContainerName, item); using var blobStream = await blob.OpenReadAsync(cancellationToken : stoppingToken).ConfigureAwait(false); var result = await handler.HandleAsync(blob.Name, blobStream).ConfigureAwait(false); if (result.HasSucceeded) { await _blobStorage.MoveBlobAsync(options.Value.ContainerName, item, leaseId, options.Value.ProcessedBlobs, stoppingToken).ConfigureAwait(false); } else { await _blobStorage.MoveBlobAsync(options.Value.ContainerName, item, leaseId, options.Value.RejectedBlobs, stoppingToken).ConfigureAwait(false); } } catch (Exception e) { _logger.LogError($"An error occurred while processing blob {item.Name}: {e.Message}"); } }