visual-studio - 发布后似乎没有触发 Azure Function App

标签 visual-studio continuous-integration c#-3.0 azure-functions azure-blob-storage

在 Azure 中,我开发了一个函数(应用服务),当一个新的 csv 文件被放置在一个特定的存储帐户中时会触发它。该函数是在 Azure 中开发的,每次上传新的 csv 文件时都不会出现问题。然而,考虑到 CI/CD,我决定将我的开发过程从 Azure 转移到 Visual Studio (2017)。

代码在本地运行没有任何问题,但是一旦我将代码发布到 Azure(通过 VSTS),挑战就开始了。当新的 csv 文件上传到存储帐户时,触发器似乎没有被激活。顺便说一句,该功能确实触发了,但我无法确定这是为什么,或重新创建它。

为了让问题更容易理解,我将我的代码减少到只有 Blobtrigger 和一些日志记录。此外,我删除了 VSTS 中的构建,并通过 Visual Studio 2017 直接发布了我的构建,但结果相似。该代码在本地运行良好,但在发布后该函数不会被触发(或非常偶然地触发)。

我使用的代码:

using System.IO;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;

namespace TestApp
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run([BlobTrigger("csv-files-in/{name}.csv", Connection = "AzureWebJobsStorage")]Stream myBlob, string name, TraceWriter log)
        {
            log.Info($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
        }
    }
}

“AzureWebJobsStorage”指的是定义了 Blobstorage 端点的 local.settings.json。此设置会自动部署到 Azure,但即使我手动设置此连接,也不会触发该功能。在我自己多次尝试解决这个问题后,我决定向本网站上的聪明人寻求建议。这是一个错误还是我错过了什么?在将其发布到 Azure 后,我该怎么做才能确保我的函数确实(可靠地)被触发?提前致谢。

最佳答案

你可能会遇到这个:

If your function app is on the Consumption plan, there can be up to a 10-minute delay in processing new blobs if a function app has gone idle. To avoid this cold-start delay, you can switch to an App Service plan with Always On enabled, or use a different trigger type.



取自 Azure Blob storage bindings for Azure Functions

触发该功能的另一种解决方案是使用 Event Grid .

编辑:
另外,请注意 BlobTrigger 是轮询触发器。没有发现任何变化的时间越长,轮询之间的时间就越长。这会给您一些可能长达数分钟的延迟。

If the blob container being monitored contains more than 10,000 blobs, the Functions runtime scans log files to watch for new or changed blobs. This process can result in delays. A function might not get triggered until several minutes or longer after the blob is created.



更多信息请访问 Azure Blob storage bindings for Azure Functions - polling

关于visual-studio - 发布后似乎没有触发 Azure Function App,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50741315/

相关文章:

android - 如何将静态代码分析 (SonarCube) 集成到移动项目的 ship.io 中?

design-patterns - 测试数据生成器是否应该为其非基元构造默认值?

visual-studio-2010 - Visual Studio 2010 : Solution Explorer not showing project directory structure

c# - 按钮内的 WPF 按钮单击问题

continuous-integration - 如何在github操作中使用pip缓存?

python - 如何在 TravisCI 中使用 python-3.6.7

.net-3.5 - 需要重构建议/想法

c# - 关于线程/后台 worker 的问题

visual-studio - 在Visual Studio中不会引发异常

ios - "Perform all 32 bit float operations as 64 bit float"MORE 还是 LESS 与 .net 兼容?