本文介绍了在Azure功能上检测超时以将消息重新路由到应用服务计划的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Azure功能,可以将消费计划中的档案解压缩.其中一些碰巧需要超过10分钟的时间才能解压缩,并且可能会超时.我正在考虑制定一个单独的应用程序服务计划,在执行消费计划时,我将在其中重新路由提取.

I've got an Azure function unziping archives on a consumption plan. Some of them happens to take more than 10min to unzip and can timeout. I'm thinking of having a separate app service plan where I would reroute the extraction when timing out on consumption plan.

您将如何做?该功能中的计时器?捕获超时异常?您有更好的建议吗?

How would you do that? a timer in the function? a catch timeout exception? Do you have a better suggestion?

谢谢

推荐答案

对于那些感兴趣的人,我结束了将自己的超时(比Azure提前几秒)添加到提取函数中,然后重新路由到服务应用程序计划处理的另一个队列比不超时.

For those interested I ended adding my own timeout (few seconds earlier than Azure one) to the extract function, then rerouting to another queue handled by a service app plan than don't timeout.

代码:

using (var timeoutCts = new CancellationTokenSource())
{
    try
    {
        // task completed within timeout
        timeoutCts.CancelAfter(590000);
        var counter = await ExtractArchiveAsync(archiveFullName, myBlob, timeoutCts.Token);
        log.Info($"Extracted : { counter.GetCurrentCount() }");
    }
    catch (OperationCanceledException)
    {
        // timeout logic
        log.Info($"Function timedout, redirected to long queue");
        var queue = StorageService.GetCloudQueueReference("ArchiveToExtractQueueTimedOut");
        await queue.AddMessageAsync(new CloudQueueMessage(archiveFullName));
    }
}

这篇关于在Azure功能上检测超时以将消息重新路由到应用服务计划的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 01:12