-
Notifications
You must be signed in to change notification settings - Fork 31
Home
HyperFlow provides a simple but powerful model of computation and execution engine for complex workflow applications. In HyperFlow, a workflow is defined as a set of processes performing well-defined functions and exchanging signals.
Programming a workflow involves: writing its model in JSON (workflow.json
) and implementing its functions in JavaScript (functions.js
).
A simple workflow which consumes a sequence of numbers and produces the sum of squares of every three of them is shown below. The workflow is composed of two processes: the first one computes the squares in parallel, the second one collects every three squares, computes their sum, and emits it as a result. Read more about available process types, and look at additional workflow examples to learn more about the HyperFlow workflow model.
This workflow is expressed in a simple JSON format as follows.
{
"name": "Wf_SumSquares",
"processes": [ {
"name": "Sqr",
"type": "dataflow",
"function": "sqr",
"parlevel": 0, // squares are computed in parallel...
"ordering": "true", // ...but the results are ordered
"ins": [ "number" ],
"outs": [ "square" ]
}, {
"name": "Sum",
"type": "dataflow",
"function": "sum",
"ins": [ "square:3" ], // 3 'square' signals are required to activate the process
"outs": [ "sum" ]
} ],
"signals": [ {
"name": "number",
"data": [ 1, 2, 3, 4, 5, 6 ]
}, {
"name": "square"
}, {
"name": "sum"
} ],
"ins": [ "number" ],
"outs": [ "sum" ]
}
The two functions used in the workflow are shown below. A function receives the input signals in the ins
array, and the information about output signals in the outs
array. The outs
array should be filled with output data and returned via a callback cb
. The engine will automatically convert returned values to signals and send them to their sinks.
function sqr(ins, outs, config, cb) {
var n = Number(ins.number.data[0]); // reading input data
outs.square.data = [n * n]; // writing output data
setTimeout(function() { // squares are computed in a random order
cb(null, outs); // returning output data to the workflow engine
}, Math.random() * 3000);
}
function sum(ins, outs, config, cb) {
var sum=0.0;
ins.square.data.forEach(function (n) { // input data contains three numbers
sum += n;
});
outs.sum.data = [ sum ];
console.log(sum);
cb(null, outs);
}