I have an Azure Durable function in which I need to read a few blobs in "blobs" path, upload a new blob and once that's complete, delete the blobs in "blobs" path
filePath = await context.CallActivityAsync<string>(nameof(UpoadFunction));
await context.CallActivityAsync<string>(nameof(DeletFunction));
// UploadFunction calls SendAsync()
public async Task<string> SendAsync()
{
string prefix = "blobs";
var blobResult = await ReadAsync(prefix);
var fileName = $"new.json";
await UploadAsync(fileName, JsonSerializer.Serialize(blobResult));
return fileName;
}
public async Task<List<AzureADUser>> ReadAsync(string path)
{
var blobs = _containerClient.GetBlobsAsync(prefix: path);
var blobReaderTasks = new List<Task<Stream>>();
await foreach (BlobItem blobItem in blobs)
{
blobReaderTasks.Add(_containerClient.GetBlobClient(blobItem.Name).OpenReadAsync());
}
var blobStreams = await Task.WhenAll(blobReaderTasks);
var blobDeserializationTasks = blobStreams
.Select(async stream =>
{
var options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
};
var users = await JsonSerializer.DeserializeAsync<List<AzureADUser>>(stream, options);
if (users == null)
{
throw new Exception("Failed to deserialize blob");
}
return users;
})
.ToArray();
var adUsers = await Task.WhenAll(blobDeserializationTasks);
return adUsers.SelectMany(userList => userList).ToList();
}
public async Task UploadAsync(string path, string content, Dictionary<string, string> metadata = null)
{
var blobClient = _containerClient.GetBlobClient(path);
await blobClient.UploadAsync(BinaryData.FromString(content), overwrite: true);
if (metadata != null && metadata.Count > 0)
blobClient.SetMetadata(metadata);
}
// DeletFunction calls DeleteAsync()
public async Task DeleteAsync(string path)
{
var blobItems = _containerClient.GetBlobsAsync(prefix: "blobs");
var deleteTasks = new List<Task>();
await foreach (BlobItem blobItem in blobItems)
{
var blobClient = _containerClient.GetBlobClient(blobItem.Name);
deleteTasks.Add(blobClient.DeleteIfExistsAsync());
}
await Task.WhenAll(deleteTasks);
}
The issue that I notice is that, if I have DeletFunction uncommented, I see less number of blobs being read & uploaded blob has less number of objects. If I have DeletFunction commented, I see it reading all the blobs & uploading blob with all objects. What am I missing?
await context.CallActivityAsync<string>(nameof(DeletFunction));



DeleteFunctiononly after the upload is completed, so the blobs will not delete while you are still using them.