首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Azure持久编排-完成编排后引发事件

Azure持久编排-完成编排后引发事件
EN

Stack Overflow用户
提问于 2021-06-24 21:53:19
回答 1查看 19关注 0票数 0

我使用Azure编排,我想在编排完成后引发一个事件:

代码语言:javascript
复制
    [FunctionName(nameof(RunComputingQueueUpdate))]
    public async Task RunComputingQueueUpdate(
        [QueueTrigger("test-route", Connection = "TestQueue:QueueConnectionString")] string message,
        [DurableClient] IDurableOrchestrationClient starter)
    {
        var command = queueCommunicator.Read<MyCommand>(message);
        var instanceId = await starter.StartNewAsync(nameof(RunOrchestratorComputing), command.PartitionKey, command);

        // How can I wait here ?
        await starter.WaitForCompletionOrCreateCheckStatusResponseAsync(new HttpRequestMessage(), instanceId);

        if (!string.IsNullOrEmpty(command.EventInstanceId) && !string.IsNullOrEmpty(command.EventName))
        {
            await starter.RaiseEventAsync(command.EventInstanceId, command.EventName, command.EventParam);
        }
    }

我想等待orchestrtaion完成,但是我不知道如何创建我的HttpRequest来完成。我需要使用client.CreateHttpManagementPayload(instanceId)吗?

提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-25 19:36:20

好吧,除了等待编排完成的while循环之外,我找不到任何其他的解决方案:

代码语言:javascript
复制
    [FunctionName(nameof(RunComputingQueueUpdate))]
    public async Task RunComputingQueueUpdate(
        [QueueTrigger("test-route", Connection = "TestQueue:QueueConnectionString")] string message,
        [DurableClient] IDurableOrchestrationClient starter)
    {
        Contract.Assume(starter != null);
        if (string.IsNullOrEmpty(message))
            throw new ArgumentNullException(nameof(message));

        var command = queueCommunicator.Read<MyCommand>(message);

        // Check if an instance with the specified ID already exists or an existing one stopped running(completed/failed/terminated).
        var existingInstance = await starter.GetStatusAsync(command.PartitionKey);
        if (existingInstance == null
            || existingInstance.RuntimeStatus == OrchestrationRuntimeStatus.Completed
            || existingInstance.RuntimeStatus == OrchestrationRuntimeStatus.Failed
            || existingInstance.RuntimeStatus == OrchestrationRuntimeStatus.Terminated)
        {
            // An instance with the specified ID doesn't exist or an existing one stopped running, create one.
            var instanceId = await starter.StartNewAsync(nameof(RunOrchestratorComputing), command.PartitionKey, command);

            // Wait the task is completed/failed/terminated
            var status = await starter.GetStatusAsync(instanceId);
            while (status.RuntimeStatus == OrchestrationRuntimeStatus.Running
                || status.RuntimeStatus == OrchestrationRuntimeStatus.Pending)
            {
                await Task.Delay(200);
                status = await starter.GetStatusAsync(instanceId);
            }

            // Raise the event
            if (!string.IsNullOrEmpty(command.EventInstanceId) && !string.IsNullOrEmpty(command.EventName))
            {
                await starter.RaiseEventAsync(command.EventInstanceId, command.EventName, eventData:command.EventParam);
            }

        }
        else
        {
            // Exception will re-enqueue the command (wait 10min by default and re-enqueue the command
            throw new Exception("Instance already running");
        }
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68117128

复制
相关文章

相似问题

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