以下if
-else
结构对于Azure持久函数编排来说是否太不确定?
[FunctionName(FUNC_NAME_ORCH0)]
public static async Task<string> RunPlayerYouTubeOrchestration(
[OrchestrationTrigger] DurableOrchestrationContext orchestrationContext,
ILogger log)
{
if (!orchestrationContext.IsReplaying)
log?.LogInformation(GetInvocationMessage(orchestrationContext, FUNC_NAME_ORCH0));
var hasExhaustedPartitions = await orchestrationContext
.CallActivityAsync<bool>(FUNC_NAME_ORCH_FUNC0, null);
if (!hasExhaustedPartitions)
{
var jsonBlobs = await orchestrationContext
.CallActivityAsync<string[]>(FUNC_NAME_ORCH_FUNC1, null);
var tasks = new Task[jsonBlobs.Length];
for (int i = 0; i < jsonBlobs.Length; i++)
{
var json = jsonBlobs[i];
tasks[i] = orchestrationContext.CallActivityAsync(FUNC_NAME_ORCH_FUNC2, json);
}
if (!orchestrationContext.IsReplaying)
log?.LogInformation($"{FUNC_NAME_ORCH0}: fan-out starting...");
await Task.WhenAll(tasks);
}
else
{
var orc1InstanceId = await orchestrationContext
.CallSubOrchestratorAsync<string>(FUNC_NAME_ORCH1, null);
if (!orchestrationContext.IsReplaying)
log?.LogInformation($"{FUNC_NAME_ORCH1} completed with instance ID `{orc1InstanceId}`.");
var orc2InstanceId = await orchestrationContext
.CallSubOrchestratorAsync<string>(FUNC_NAME_ORCH2, null);
if (!orchestrationContext.IsReplaying)
log?.LogInformation($"{FUNC_NAME_ORCH2} completed with instance ID `{orc2InstanceId}`.");
if (!orchestrationContext.IsReplaying)
log?.LogInformation($"{FUNC_NAME_ORCH_FUNC3}: calling `{PlayerYouTubeIndicesActivity.ProcedureNameResetYouTubePartitionInfoAsync}`...");
await orchestrationContext
.CallActivityAsync(FUNC_NAME_ORCH_FUNC3,
PlayerYouTubeIndicesActivity.GetInput(
PlayerYouTubeIndicesActivity.ProcedureNameResetYouTubePartitionInfoAsync));
}
return orchestrationContext.InstanceId;
}
hasExhaustedPartitions
不能很好地与replay一起工作吗?如果是,那么必须做些什么呢?
发布于 2020-03-25 00:49:22
当计算的条件是确定性的时,if/else没有什么问题。在您的示例中,FUNC_NAME_ORCH_FUNC0
函数将执行一次,结果将记录在历史中,并且记录的结果将用于在所有后续重放中初始化hasExhaustedPartitions
变量,因此条件是确定性的。
https://stackoverflow.com/questions/60819603
复制相似问题