Coder Social home page Coder Social logo

aws-swf's Introduction

A Node.js library for accessing Amazon Simple Workflow (SWF)

NPM version Build Status Coverage Status Code Climate

aws-swf provides high-level classes to build Amazon Simple Workflows using Node.js.

It is built on top of the official Node.js aws-sdk for low-level API calls. You can find the full API reference here.

Requirements

Installation

npm install aws-swf

Setting AWS Credentials

Cf. http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html#Setting_AWS_Credentials

Usage

Step 1 : Register Domains, ActivityTypes, WorkflowTypes

The AWS SDK is sufficient to register SWF objects, since those are just direct API calls. (You can also register them through the AWS console.)

You can run the following example to register the objects used in the following examples :

Example to register "test-domain", "simple-activity" and "simple-workflow"

Step 2 : Create Activity Workers

An ActivityPoller will wait for new tasks from SWF, and emit an activityTask event. The event receives an instance of ActivityTask, which makes it easier to send the response to SWF.

This example starts an Activity Worker which completes immediatly.

Step 3 : Create Workflow Deciders

The Decider class will wait for new decision tasks from SWF, and emit a decisionTask event. The event receives an instance of DecisionTask, composed of :

  • an EventList instance, to query the state of the workflow
  • a DecisionResponse instance, to prepare the decider response with decisions

Simple decider worker example : decision worker, which schedules an activity task, then stop the workflow.

Step 4 : Start a workflow

To start a workflow, call the start method on a Workflow instance. This call will return a WorkflowExecution instance, which you can use to signal or terminate a workflow.

AWS Options

Sometimes you may want to configure the AWS SDK instance. A possible reason is to set a specific region for aws-swf. Because Node.js allows multiple instances of the same package for maximal compatibility among libraries, you would need to do something similar to:

var AWS = require('./node_modules/aws-swf/node_modules/aws-sdk/lib/aws');

Instead, you simlpy need to do:

var AWS = require('aws-swf').AWS;

An example use case would be:

var AWS = require('aws-swf').AWS;

AWS.config = new AWS.Config({
  region: process.env.AWS_REGION || 'us-west-2',
  apiVersions: {
    swf: '2012-01-25'
  }
});

API Documentation

The API documentation is available online at http://neyric.github.io/aws-swf/apidoc/

To rebuild the documentation, install jsdoc, then :

jsdoc lib/*.js README.md -d apidoc

Test

Tests can be executed with Mocha :

$ mocha

To get the coverage, run :

$ ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha

Then open coverage/lcov-report/index.html

To send the coverage to coveralls, I run locally (I don't know why travis-ci after-script doesn't work...):

$ NODE_ENV=test ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | COVERALLS_REPO_TOKEN=xxxx ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage

License

MIT License

See also

aws-swf's People

Contributors

ericabouaf avatar mdlavin avatar melnicki avatar sukrit007 avatar trym avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.