Comparing version 0.0.7 to 0.0.8
@@ -1,26 +0,25 @@ | ||
var workflow = require('./src/tasks') | ||
var workflow = require('../') | ||
var taskDefinition = workflow.define( | ||
{ task: "sequence", items: [ | ||
{task:"log", message:"hello there"}, | ||
{task:"log"}, | ||
{task:"delay", duration:1200}, | ||
{task:"set", name:"a", value:"b"}, | ||
{task:"log", message:"@a" }, | ||
{task:"sequence", items: [ | ||
{task:"log", message:"@"}, | ||
{task:"log"} | ||
]}, | ||
{ task:"parallel", items: [ | ||
{task:"delay", duration:1200}, | ||
{task:"log"}, | ||
{task:"log"} | ||
]} | ||
] | ||
{ task: "sequence", items: [ | ||
{task:"log", message:"hello there"}, | ||
{task:"log"}, | ||
{task:"delay", duration:1200}, | ||
{task:"set", name:"a", value:"b"}, | ||
{task:"log", message:"@a" }, | ||
{task:"sequence", items: [ | ||
{task:"log", message:"@"}, | ||
{task:"log"} | ||
]}, | ||
{ task:"parallel", items: [ | ||
{task:"delay", duration:1200}, | ||
{task:"log"}, | ||
{task:"log"} | ||
]} | ||
] | ||
}); | ||
var ctx = {} | ||
var task = taskDefinition(ctx); | ||
task(function(err, result) { | ||
console.log("executed", ctx); | ||
var task = taskDefinition(ctx, function(err, result) { | ||
console.log("executed", ctx); | ||
}); | ||
@@ -27,0 +26,0 @@ |
@@ -28,2 +28,3 @@ var debug = require( 'debug')('workflow:common') | ||
define: function (workflowDefinition) { | ||
debug("defining: %s", workflowDefinition.task) | ||
@@ -80,2 +81,5 @@ var WorkflowType = workflow.getWorkflow(workflowDefinition.task) | ||
return function build(context) { | ||
if (arguments.length == 2) { | ||
return build(arguments[0])(arguments[1]) | ||
} | ||
var decorated = wfInstance(context) | ||
@@ -82,0 +86,0 @@ debug("preparing: %s", workflowDefinition.task) |
{ | ||
"name": "worksmith", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "A purely functional workflow engine ", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,14 +5,17 @@ # WorkSmith | ||
A seriously ```functional``` workflow library. | ||
A seriously ```functional``` workflow library, that lets you build composable and configurable process definitions for various reasons. | ||
Compose hyper complex async program parts in a way that is easy to understand and also to maintain, and favors configuration over coding. | ||
- Use prebuilt activites like ```sequence``` or ```parallel``` or the ```warezSequence``` to manage program flow | ||
- Use the conditional property to opt out from workflow steps on condition | ||
- Use "@propertyname" to reference values on the workflow context | ||
- Use {template: "{{xy}}/{{asd}}" to access the context with a templating engine | ||
## Highlights | ||
- WorkSmith comes with an extensible task library | ||
- Control flow: ```sequence``` , ```parallel``` and ```warezSequence``` | ||
- IO: ```log```,```sql/pg``` | ||
- Tansformation: ```map```, ```regex```, ```set``` | ||
- Extensibitly: ```code``` task type, create custom task types by creating files in the tasks folder | ||
- with WorkSmith you can build a complex async process chain from functional steps (tasks) - yet keep the application easy to understand and each functional step easy to developer and maintain. forget ```if(err) return next(err)``` | ||
- workflow steps are unaware about each other - they communicate over a shared context. WorkSmith provides an intuitive expression syntax for working with the context in a workflow definitions | ||
## usage | ||
### The workflow definition: | ||
### A workflow definition: | ||
@@ -23,7 +26,9 @@ ```javascript | ||
{ | ||
task: "set", | ||
value: ["some_id", 1, 1], | ||
resultTo: "@insertParams" | ||
task:"log", message:"hello workflow" | ||
}, | ||
{ | ||
task: "map", | ||
">insertParams": ["@req.params.id", 1, 1] | ||
}, | ||
{ | ||
task:"sql/pg", | ||
@@ -47,23 +52,20 @@ connection: "@connection", | ||
var workflow = worksmith('./workflow.json') | ||
var Workflow = worksmith('./workflow.json') | ||
var context = {connection:"postgres://login:pw@host/db", other:"data"} | ||
var context = { | ||
connection:"postgres://login:pw@host/db", | ||
other:"data" | ||
} | ||
var task = Workflow(context); | ||
workflow(context, function(err, result) { | ||
console.log("workflow completed, %", context.insertResult) | ||
}) | ||
task(function(err, result) { | ||
console.log("workflow completed, context potentially changed") | ||
}) | ||
``` | ||
mini-workflow has some core workflow task types for controlling process flow. These are the | ||
-sequence | ||
-parallel | ||
-warezSequence | ||
activities | ||
## How to create your own activity | ||
mini-workflow lets you build your activities on a super easy way | ||
WorkSmith lets you build your activities on a super easy way | ||
Place the following code as ```"hello-world.js"``` in the ```tasks``` folder | ||
@@ -80,4 +82,4 @@ | ||
//read and write data from the context | ||
console.log("Hello world", utils.readValue(node.inParam, context)) | ||
utils.setValue(context,"myresult","myvalue") | ||
console.log("Hello world", context.get(node.inParam)) | ||
context.set("myresult","myvalue") | ||
done(); | ||
@@ -91,8 +93,6 @@ } | ||
```javascript | ||
var wf = workflow.define({ "task": "sequence", | ||
"items": [ | ||
{"task":"hello-world", "inParam":"some thing"} ]}); | ||
var wf = workflow( {"task":"hello-world", "inParam":"some thing"} ); | ||
var ctx = {"some":"value"}; | ||
wf(ctx)(function(err) { | ||
wf(ctx, function(err) { | ||
console.log(ctx) | ||
@@ -99,0 +99,0 @@ }) |
var async = require('async') | ||
var workflow = require('./') | ||
var workflow = require('../') | ||
@@ -4,0 +4,0 @@ module.exports = function(node) { |
35773
783