简体   繁体   English

亚马逊简单工作流程-并行处理任务,仅在上一阶段的所有并行过程完成后才进入下一阶段

[英]amazon simple workflow- processing tasks in parallel and going to next stage only after all parallel processes of previous stage are complete

I am working to create an app in which there are multiple stages- in the first stage there are multiple tasks to be executed in parallel...once all tasks of that stage have been completed, only then processing should go to next stage. 我正在创建一个包含多个阶段的应用程序-在第一个阶段中,有多个任务要并行执行...一旦完成该阶段的所有任务,然后处理就应该进入下一个阶段。

From what I read about deciders, deciders can choose from one of many possible options for the next stage. 根据我对决策者的了解,决策者可以从下一阶段的众多可能选项中进行选择。

But I want to go to next stage only when all parallel processes of current stage are complete. 但是我只想在当前阶段的所有并行过程都完成后才进入下一阶段。

Does this mean that I should set up each parallel process to invoke the next stage, and when the next stage is initialised, it should check if all parallel processes of previous stage are complete, and only then actually start processing? 这是否意味着我应该设置每个并行进程来调用下一阶段,并且在初始化下一阶段时,应该检查上一步的所有并行进程是否都已完成,然后才真正开始处理? This will mean that all the parallel processes of first stage will invoke corresp. 这意味着第一阶段的所有并行过程都将调用corresp。 parallel processes of second stage, out of which only one will actually do processing (since this will be the process that finds that all processes of previous stage are complete). 第二阶段的并行过程,其中只有一个实际上会进行处理(因为这是发现前一阶段的所有过程均已完成的过程)。

Is there a better way of implementing this? 有没有更好的方法来实现这一点? So that the process of next stage is called only once? 这样,下一阶段的过程仅被调用一次?

This can be solved using Promise objects returned by activities in flow framework . 这可以使用流框架中的活动返回的Promise对象来解决。

In your decider code, have a function for stage1 which will execute multiple activities in parallel each returning a Promise object. 在您的决策程序代码中,为stage1提供一个函数,该函数将并行执行多个活动,每个活动均返回一个Promise对象。 Add all these promise objects in a List<Promise<>> and pass this List to an asynchronous method which handles stage 2. 将所有这些List<Promise<>>对象添加到List<Promise<>>然后将此List传递给处理阶段2的异步方法。

Here is a sample decider code. 这是示例决策者代码。 stage1() executes three activities in parallel and calls asynchronous method stage2(@Wait List<Promise<Void>> promiseList) . stage1()并行执行三个活动,并调用异步方法stage2(@Wait List<Promise<Void>> promiseList) stage2 will not be started unless all the promises in promiseList are satisfied, ie unless all three activities in stage1 have completed. 除非promiseList中的所有promise都满足,否则,除非stage1中的所有三个活动都已完成,否则stage2将不会启动。

private void stage1() {
    List<Promise<Void>> promiseList = new ArrayList<Promise<Void>>();
    Promise<Void> promise1 = activityClient.activity1();
    Promise<Void> promise2 = activityClient.activity2();
    Promise<Void> promise3 = activityClient.activity3();

    promiseList.add(promise1);
    promiseList.add(promise2);
    promiseList.add(promise3);

    stage2(promiseList);
}

@Asynchronous
private void stage2(@Wait List<Promise<Void>> promiseList) {
    activityClient.activity4();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM