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

Azure Durable Orchestration - Raise event after the orchestration is completed

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

    [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) 吗?

提前致谢!

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

    [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");
        }
    }