Skip to content

Create new activities

neyric edited this page Jan 13, 2013 · 4 revisions

Most of the activities expect parameters to be passed in JSON format

1. Create the package.json

  • name of the activity type
  • main: worker module
  • add dependencies
  • "private": true, because those packages are not meant to be published...

2. create the worker module

exports.worker = function(task, config) {
   
   var input_parameters = task.config.input; // or JSON.parse(task.config.input)
   
   var result = f(input_parameters); // might be asynchronous
   
   // Send the response to AWS SWF
   task.respondCompleted(result, function(err) {
      if(err) { console.error(err); return; }
      console.log("echo: respondComplete");
   });
   
};

3. Config files (optional)

Write config files into config.js.

They should contains private stuff: credentials, passwords, oauth token, etc...

4. Write a test (optional)

Usually test.js

5. Test on SWF

  • create a decider which will just perform your task
  • run a swf-activity worker
  • run a swf-decider
  • start your workflow

6. Activity Deamons

Some activities require a background deamon, which is called by an external process to mark the activity as completed.

Here are the activities which currently use a deamon :

  • mturk : poll Amazon Mechanichal Turk for new assignements, and mark the activities as completed
  • WebDriver : runs phantomJS in the background
  • humantask : HTTP server to display the activity in a browser

To start those deamons, use the npm start command :

$ cd activities/mturk/
$ npm start

You must add the following line to your package.json if your activity requires a deamon :

"scripts": {"start": "node server.js"}