Skip to content
neyric edited this page Dec 31, 2012 · 3 revisions

This small tutorial will use the examples in the examples/ directory.

Step1: register all components

First we need to register a domain :

$ swf-register -k domain aws-swf-test-domain

We then register all workflows from examples/workflows :

$ cd examples/workflows
$ swf-register

Finally, we will register all activity types from examples/activities :

$ cd examples/activities
$ swf-register

Step2: run the decider, and the activity poller

Launch a decider Poller:

$ cd examples/workflows
$ swf-decider

Launch an Activity Poller:

$ cd examples/activities
$ swf-activity

Step3: Start the workflow !

$ swf-start hello-workflow "{\"a\":4,\"b\":6}"

Step4: How does this first example works

First, let's have a look at the first decider example :

// step1 -> step2 -> terminate

if (just_started) {

    schedule('step1', {
        activityType: 'hello-activity',
        input: {}
    });

} else if (completed('step1') && !scheduled('step2')) {

    schedule('step2', {
        activityType: 'echo',
        input: results('step1')
    });
} else if (completed('step2')) {
    stop("finished !");
}

What happened ?

  • The hello-workflow is started on SWF through the swf-start command, with the string "{"a":4,"b":6}" as input
  • SWF: schedules a Decision task
  • DECIDER: Receives the decision task. As just_started is true, the step1 is scheduled.
  • SWF: schedules the step1 activity
  • ACTIVITY: Receives the activity task. The echo task will return as "result" what it as been given as input (ie the "{"a":4,"b":6}" string...)
  • SWF: receives step1 results and schedule a decision task
  • DECIDER: receives the decision task. This time, step1 is completed, but step2 is not completed, so step2 is scheduled
  • SWF: schedules the step2 activity
  • ACTIVITY: Receives the activity task. The sum task will decode its input (in JSON format), and return the sum of a and b
  • SWF: receives step2 results and schedule a decision task
  • DECIDER: receives the decision task. step2 is completed so we send a CompleteWorkflowExecution through the stop() function
  • SWF: mark the workflow execution as completed
Clone this wiki locally