【问题标题】:Using Task.Delay inside an Azure Durable Function Activity在 Azure Durable Function Activity 中使用 Task.Delay
【发布时间】:2019-10-01 13:23:20
【问题描述】:

可以像这样在 Azure Durable Function Activity 中使用 Task.Delay 吗?

我正在轮询存储中应在 20-30 秒左右到达的数据。

 while (requestAccepted && retryCount < 8)
        {
            object savedData = await DataManagementService.GetSessionData(processSessionId);

            if (savedData != null && savedData.GetType().GetProperties().Any())
            {
                return true;
            }

            await Task.Delay(TimeSpan.FromSeconds(10));

            retryCount++;
        }

使用context.CreateTimer 的函数计时器功能,解释为here,仅适用于 Azure Orchestration 函数,不适用于 Activity 函数。

【问题讨论】:

    标签: azure-functions azure-durable-functions


    【解决方案1】:

    使用Task.Delay() 是完全可以的,只要您愿意为函数等待时的死时间支付费用,并且您知道它会在超时之前完成。

    但是,更好的选择是将GetSessionData() 调用移动到活动函数中,将此轮询函数转换为协调器,以便您可以将Task.Delay() 替换为context.CreateTimer(),并通过context.CallSubOrchestratorAsync() 从主协调器调用它.

    【讨论】:

    • 当然,我也考虑过按照您描述的方式重构它,但发现 CreateTimer 支持超时场景,并没有真正进行轮询场景。我可以将其进一步扩展到外部等待模式,但这对于我正在做的事情来说太迷人了。 ;o)
    • 请记住在活动中使用它,而不是直接在编排中使用。按照目前的情况,后者行不通。
    猜你喜欢
    • 1970-01-01
    • 2022-01-03
    • 2020-05-29
    • 1970-01-01
    • 2021-01-07
    • 1970-01-01
    • 1970-01-01
    • 2021-10-13
    • 2020-01-04
    相关资源
    最近更新 更多