我使用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)吗?
提前感谢!
发布于 2021-06-25 19:36:20
好吧,除了等待编排完成的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");
}
}https://stackoverflow.com/questions/68117128
复制相似问题