0
votes

I have Azure-function: blob-trigger. When I add or change a blob in the specified folder, function changes this blob.

But there is one problem. After changing the blob by the function it launchs again to process already changed blob. Then again. Thus, the function cycles.

What can I do to prevent the function from cycling?

1
Just thinking out loud, you could write the changed blob to another container. - Gaurav Mantri

1 Answers

0
votes

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.