npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

swfp

v2.2.2

Published

A framework for building applications on AWS SWF using Promises

Downloads

54

Readme

swfP

A framework for building applications on AWS SWF using Promises

swfP makes it easier to build decision and activity workers on AWS SWF by using Promises (via Bluebird) in two ways:

  • Workflow definition

    A decider is implemented as a Promise chain. By treating primitives such as activities, timers and child workflows as Promises, it becomes easy to implement parallel and serial execution with .all() and .then()

  • Activity execution

    An activity's implementation may return a Promise. This allows an activity to declare success or failure based upon fulfillment or rejection.

Usage

Install with:

npm install --save swfp

Decider

A decider is implemented as a module, which exports a single function. When called, this function should return a Promise, like so:

module.exports = (input, schedule) =>
  schedule.Promise
    .all([
  	  schedule.activity('firstUpper', input),
	  schedule.activity('restLower', input)
    ])
    .then(parts => schedule.activity('concat', parts));

The decider function accepts parameters input (which refers to the original workflow input) and schedule, which exposes the following properties:

  • Promise Refers to Bluebird instead of the ES6 implementation

  • activity(name, input, options) Starts an activity named name with input parameter input. Additional, optional SWF attributes may be specified with options.

    Returns a Promise which is resolved with the returned result of the Activity when it completed, or rejects with the error when it fails.

  • timer(name, seconds) Starts a Timer with name.

    Returns a Promise which resolves to null after seconds have elasped.

  • childWorkflow(name, input, options) Starts an activity named name with input parameter input. Additional, optional SWF attributes may be specified with options.

    Returns a Promise which is resolved with the returned result of the Workflow when it completed, or rejects with the error when it fails.

  • signal(name) Returns a Promise which is resolved to the value given when a signal named name was called on the current Workflow execution

You can then start a worker for this decider by invoking the following command:

swfp-decider --file=./decider.js --domain=myDomain --taskList=myTasks

Activity Worker

An activity worker exports an object containing activity implementations, like so:

module.exports = {
	firstUpper: str => str[0].toUpperCase(),
	restLower:  str => str.substring(1).toLowerCase(),
	concat:     str => str.join('')
};

Each exported function accepts a single parameter, which is the input value that was supplied to the activity's invocation when it was executed by the Workflow.

Each exported function may do one of the following:

  • Return a non-Promise value to mark the execution as successful
  • Throw an Error to mark the execution as failed
  • Return a Promise to mark the execution as succesful or failed when the Promise is settled

You can then start a worker for these activites by invoking the following command:

swfp-worker --file=./tasks.js --domain=myDomain --taskList=myTasks

Caveats and Notes

  • The Promise chain that a Decider exports only gives the illusion of a persistent state; the Decision poller destroys the object at the end of each decision execution.
  • If you use any Promises within the Decider outside of those described here, they must resolve before the next tick, or the decider will hang.
  • If you need to execute long-running code, implement it as an Activity instead.