首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >必须在业务流程客户端上等待StartNewAsync吗?

必须在业务流程客户端上等待StartNewAsync吗?
EN

Stack Overflow用户
提问于 2020-02-27 03:30:44
回答 2查看 1.9K关注 0票数 1

我有一个Azure业务流程,其中触发业务流程的编排客户端抛出了一个超时异常。

业务流程客户端函数只做两件事,启动两个编排,等待每个流程,正如大多数示例代码所建议的那样。

代码语言:javascript
复制
await orchestrationClient.StartNewAsync("TableOrchestrator", updates);
await orchestrationClient.StartNewAsync("ClientOrchestrator", clientExport);

然而,正如我所理解的,编排客户端并不像编排函数那样是一个特殊的函数,因此它只能运行10分钟。显然,我的两个管弦乐的综合运行时间很有可能超过10分钟。

问题:

  1. 业务流程客户端状态是否保存为实际的业务流程函数?
  2. 我是否需要等待它们不依赖于以前的编排结果的编排?

Update提供了一个完整的示例,说明了我的代码所做的工作,以及运行时,如下所示。

如果后面有编写的代码,那么启动业务流程将等待它,但如果编制是最后一条语句,则不会!

更新问题:

  1. 调用StartNewAsync()之后的任何代码会使函数等待业务流程真正完成吗?或者,日志语句不会触发这种行为吗?
  2. 建议的代码实践是,只有在执行了所有其他代码之后才应该调用StartNewAsync()吗?

代码语言:javascript
复制
public static class testOrchestration
{
    [FunctionName("Start")]
    public static async Task Start([TimerTrigger("0 */30 * * * *", RunOnStartup = true, UseMonitor = false)]TimerInfo myStartTimer, [OrchestrationClient] DurableOrchestrationClient orchestrationClient, ILogger log)
    {
        var startTime = DateTime.Now;
        log.LogInformation(new EventId(0, "Startup"), "Starting Orchestror 1 ***");

        await orchestrationClient.StartNewAsync("Orchestrator", "ONE");
        log.LogInformation($"Elapsed time, await ONE: {DateTime.Now - startTime}");

        await Task.Delay(5000);
        log.LogInformation($"Elapsed time, await Delay: {DateTime.Now - startTime}");

        log.LogInformation(new EventId(0, "Startup"), "Starting Orchestror 2 ***");
        await orchestrationClient.StartNewAsync("Orchestrator", "TWO");
        log.LogInformation($"Elapsed time, await TWO: {DateTime.Now - startTime}");
    }


    [FunctionName("Orchestrator")]
    public static async Task<string> TestOrchestrator([OrchestrationTrigger] DurableOrchestrationContextBase context, ILogger log)
    {
        var input = context.GetInput<string>();
        log.LogInformation($"Running {input}");
        await Task.Delay(5000);

        return $"Done {input}";
    }
}

运行此操作将给出以下输出:

代码语言:javascript
复制
Starting Orchestror 1 ***
Elapsed time, await ONE: 00:00:08.5445755
Running ONE
Elapsed time, await Delay: 00:00:13.5541264
Starting Orchestror 2 ***
Elapsed time, await TWO: 00:00:13.6211995
Running TWO
EN

回答 2

Stack Overflow用户

发布于 2020-02-27 09:16:52

StartNewAsync()只是安排了要启动的编排器(立即)。等待这些调用并不意味着您的初始函数将真正等待协调器运行-甚至实际开始和完成它的工作。

编排客户端绑定上的StartNewAsync (.NET)或startNew (JavaScript)方法将启动一个新实例。在内部,此方法将消息排队到控制队列中,然后控制队列将触发使用编排触发器绑定的指定名称的函数的开始。 此异步操作在业务流程成功调度时完成,

来源

此异步操作在成功调度业务流程时完成。

所以是的:你应该等待这些电话(也可以像米格尔建议的那样并行进行)。但它不会超过几毫秒。

票数 5
EN

Stack Overflow用户

发布于 2020-02-27 03:51:19

如果它们不相互依赖,则可以使用以下方法并行运行它们:

代码语言:javascript
复制
var t1 = orchestrationClient.StartNewAsync("TableOrchestrator", updates);
var t2 = orchestrationClient.StartNewAsync("ClientOrchestrator", clientExport);
await Task.WhenAll(t1, t2);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60425865

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档