简体   繁体   English

等待 azure function 持久编排完成

[英]Waiting for an azure function durable orchestration to complete

Currently working on a project where I'm using the storage queue to pick up items for processing.目前正在从事一个项目,我正在使用存储队列来挑选要处理的项目。 The Storage Queue triggered function is picking up the item from the queue and starts a durable orchestration.存储队列触发 function 正在从队列中拾取项目并启动持久编排。 Normally the according to the documentation the storage queue picks up 16 messages (by default) in parallel for processing ( https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue ), but since the orchestration is just being started (simple and quick process), in case I have a lot of messages in the queue I will end up with a lot of orchestrations running at the same time.通常根据文档,存储队列会并行处理 16 条消息(默认情况下)( https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue ) ,但是由于编排刚刚开始(简单快速的过程),如果我在队列中有很多消息,我最终会同时运行很多编排。 I would like to be able to start the orchestration and wait for it to complete before the next batch of messages are being picked up for processing in order to avoid overloading my systems.我希望能够启动编排并等待它完成,然后再拾取下一批消息进行处理,以避免系统过载。 The solution I came up with and seems to work is:我提出并似乎有效的解决方案是:

public class QueueTrigger
    {
        [FunctionName(nameof(QueueTrigger))]
        public async Task Run([QueueTrigger("queue-processing-test", Connection = "AzureWebJobsStorage")]Activity activity, [DurableClient] IDurableOrchestrationClient starter,
            ILogger log)
        {
            log.LogInformation($"C# Queue trigger function processed: {activity.ActivityId}");
            string instanceId = await starter.StartNewAsync<Activity>(nameof(ActivityProcessingOrchestrator), activity);            

            log.LogInformation($"Started orchestration with ID = '{instanceId}'.");

            var status = await starter.GetStatusAsync(instanceId);
            do
            {
                status = await starter.GetStatusAsync(instanceId);
            } while (status.RuntimeStatus == OrchestrationRuntimeStatus.Running || status.RuntimeStatus == OrchestrationRuntimeStatus.Pending);
        }

which basically picks up the message, starts the orchestration and then in a do/while loop waits while the staus is Pending or Running.它基本上接收消息,启动编排,然后在 do/while 循环中等待状态为 Pending 或 Running。 Am I missing something here or is there any better way of doing this (I could not find much online).我在这里遗漏了什么或者有更好的方法吗(我在网上找不到太多)。 Thanks in advance your comments or suggestions!提前感谢您的意见或建议!

This might not work since you could either hit timeouts causing duplicate orchestration runs or just force your function app to scale out defeating the purpose of your code all together.这可能行不通,因为您可能会遇到超时导致重复的编排运行,或者只是强制您的 function 应用程序横向扩展,从而完全破坏您的代码的目的。

Instead, you could rely on the concurrency throttles that Durable Functions come with.相反,您可以依赖 Durable Functions 附带的并发限制 While the queue trigger would queue up orchestrations runs, only the max defined would run at any time on a single instance of a function.虽然队列触发器会将编排运行排队,但只有定义的最大值会随时在 function 的单个实例上运行。

This would still cause your function app to scale out, so you would have to consider that as well when setting this limit and you could also set the WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT app setting to control how many instances you function app can scale out to.这仍然会导致您的 function 应用程序向外扩展,因此您在设置此限制时也必须考虑到这一点,您还可以设置WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT应用程序设置来控制您的 function 应用程序可以扩展到多少个实例。

It could be that the Function app's built in scaling throttling does not reduce load on downstream services because it is per app and will just cause the app to scale more.可能是 Function 应用程序的内置扩展限制不会减少下游服务的负载,因为它是针对每个应用程序的,只会导致应用程序扩展得更多。 Then what is needed is a distributed max instance count that all app instances adhere to.然后需要的是所有应用程序实例都遵守的分布式最大实例数。 I have built this functionality into my Durable Function orchestration app with a scaleGroupId and it`s max instance count.我已将此功能构建到我的 Durable Function 编排应用程序中,其中包含一个 scaleGroupId 及其最大实例数。 It has an Api call to save this info and the scaleGroupId is a string that can be set to anything that describes the resource you want to protect from overloading.它有一个 Api 调用来保存此信息,scaleGroupId 是一个字符串,可以设置为任何描述您想要防止超载的资源的字符串。 Here is my app that can do this:这是我的可以执行此操作的应用程序:

Microflow微流

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure 耐用 function 崩溃了 - Azure Durable function is crashing out Python Azure 计时器 Function 带耐用实体 - Python Azure Timer Function with Durable Entity 并行运行 Azure 耐用 Function 的问题 - Problem Running Azure Durable Function in parallel 有没有办法阻止持久 azure function 的启动? - Is there a way to prevent start of a durable azure function? Azure 耐用 Function 可以运行多长时间? - How long can an Azure Durable Function run for? Azure Function 长期和应用服务计划,持久 function - Azure Function long duration and App Service Plan, Durable function Azure 持久 function 多个版本的部署选项 function 应用程序 - Azure durable function deployment options for multiple versions of a function app 当 function 应用程序链接到 static web 应用程序时,如何获取 Azure 持久功能的状态? - How to get status of Azure durable functions when the function app is linked to a static web application? 持久 Function 异常:“无法找到用于此绑定的 Azure 存储连接字符串。” - Durable Function exception: "Unable to find an Azure Storage connection string to use for this binding." “未找到存储连接字符串。” 当试图从 azure 功能核心工具中列出持久的 function 实例时 - 'No storage connection string found.' when trying to list durable function instances from azure functions core tools
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM