What can I do to prevent the function from cycling?
One way is storing the ETag of modified blob and comparing the ETag before modifying the blob. If the ETag is already exist, it means the blob has just been modified. We don't need to anything with this blob. Code below is for your reference.
public static void ProcessBlob([BlobTrigger("mycontainer/{name}")] CloudBlockBlob blob, string name)
{
Console.WriteLine("before check:" + blob.Properties.ETag);
if (CheckETagExists(blob.Properties.ETag))
{
//Do nothing
}
else
{
//Modify this blob
//...
//After modified this blob, save the ETag of this blob to a place.
blob.UploadText("abcdefg");
SaveETag(blob.Properties.ETag);
Console.WriteLine("Save:" + blob.Properties.ETag);
}
}
public static bool CheckETagExists(string etag)
{
return ModifiedBlobETags.Contains(etag);
}
public static void SaveETag(string etag)
{
ModifiedBlobETags.Add(etag);
}
public static List<string> ModifiedBlobETags = new List<string>();
The sample save the ETags to memory for test purpose, I suggest you save the ETags to persist files or Azure Table Service for your function.