AWS SWF – 通过信号传递活动结果驱动工作流程

huangapple go评论90阅读模式
英文:

AWS SWF - Workflow passing activity results with signals driving the workflow

问题

我有使用AWS Simple Workflow (SWF)来设计一种编排型系统的需求。有一个父应用程序启动了这个子工作流,然后发出信号以让工作流开始执行活动。我有一个工作流,在开始执行活动之前,它会启动并等待信号。一旦一个活动完成,它将通过关闭父工作流上的活动来报告。

我如何等待信号并使用由信号调用的另一个活动的结果?

我需要查看活动的执行历史以获取结果,而不是依赖于在决策中执行此工作吗?

感谢您的帮助

示例代码:

英文:

I have the requirement to use AWS Simple Workflow (SWF) for an orchestration type of system design. There is parent application that is start this child workflow then signal the workflow to work on activities. I have a workflow that starts up and waits for signals to happen before it can start doing activity work. Once one activity is done then it will report back to by closing out the activity on the parent workflow.

How do I wait for the signal and also use the results from another activity that was invoked by a signal?

Do I need to look into the execution history for the result of an activity and not rely on doing this work in the decide?

Thanks for the help

Code Example:

@SuppressWarnings("unused")
@Slf4j
public class ChildWorkflowImpl implements ChildWorkflow {
    private final Settable<Message> firstStepReceived = new Settable<>();
    private final Settable<Message> secondStepReceived = new Settable<>();


    @Autowired
    private FirstActivityClient firstActivityClient;

    @Autowired
    private SecondActivityClient secondActivityClient;


    @Autowired
    private AmazonSimpleWorkflow amazonSimpleWorkflow;

    @Override
    public void startWorkflow(SubsystemMessage subsystemMessage) {

        //wait for signal to start
        new Task(firstStepReceived) {
            @Override
            protected void doExecute() throws Throwable {
                //Initiate Activity

                startStage(firstStepReceived.get(););
            }
        };

        //wait for second signal but pass in data from first activity
        new Task(secondStepReceived) {
            @Override
            protected void doExecute() throws Throwable {

            }
        };


    }

    public void firstStep(Message message) {
        Promise<FirstActivityResponse> firstActivity = firstActivityClient.execute();

        //wait for signal for disable
        new Task(firstActivity) {
            public void doExecute() {
                //report back status for stage by closing parent activity
            }
        };
    }

    public void secondStep(FirstActivityResponse response) {
        Promise<SecondActivityResponse> secondActivityResponse = secondActivityClient.execute(response);

        new Task(secondActivityResponse) {
            public void doExecute() {
                //report back status for stage
            }
        };

    }
}

答案1

得分: 1

你在工作流接口中添加一个信号方法,并使用Settable来通知工作流代码的其他部分有关该信号的信息。请查看此文档页面上的Settable文档。

顺便说一下,我建议查看temporal.io,这是SWF的大幅改进版本,支持无需所有这些繁琐任务的同步编程。

英文:

You add a signal method to the workflow interface and use Settable to notify the other part of the workflow code about the signal. See Settable documentation from this documentation page.

BTW. I recommend looking at temporal.io which is a greatly improved version of SWF which supports synchronous programming without all these pesky tasks.

huangapple
  • 本文由 发表于 2020年8月11日 03:14:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/63346610.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定