循环天蓝色功能(Blob触发) [英] Cycling azure-function (Blob-trigger)

查看:60
本文介绍了循环天蓝色功能(Blob触发)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有Azure功能:Blob触发.当我在指定文件夹中添加或更改Blob时,函数会更改此Blob.

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

但是有一个问题.通过功能更改Blob后,它将再次启动以处理已更改的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?

推荐答案

我该怎么做才能防止该功能循环?

What can I do to prevent the function from cycling?

一种方法是存储修改后的Blob的ETag,并在修改Blob之前比较ETag.如果ETag已经存在,则表示该Blob刚刚被修改.这个Blob不需要任何东西.以下代码供您参考.

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>();

该示例将ETag保存到内存中以进行测试,建议您将ETag保存为持久性文件或Azure Table Service以实现功能.

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.

这篇关于循环天蓝色功能(Blob触发)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆