0.0.1 • Published 8 years ago

fluo.js v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
8 years ago

FLUO

Fluo is a workflow manager interface.

Install

npm install fluo.js 
var Fluo = require('fluo.js'); 

Config Fluo

You can create an instance with a config.

var fluo = Fluo(config);

Possible values

{
	concurrentWorkflows: 20 //default 5
	runMissingWorkflows: true or false //default false
	workflowUuid: true or false //default true
	log: {
	  // TBD
	}
}

You can pass a logger to the constructor, the logger has to have the functions info and error.

How to create tasks

fluo.task('trasform-x', function(input, conf, solve, reject) {
  // conf will contain the log object, the uuid.
  // do something with the input
  // when ready call solve with the new result
  solve(input + 1);
  // if something bad happens you can call reject
  reject(reason);
});

hook

You can add a function to be excecuted when the workflow ends.

fluo.task('trasform-x', function(input, conf, solve, reject) {
  // conf will contain the log object, the uuid.
  // do something with the input
  // when ready call solve with the new result
  solve(input + 1);
  // if something bad happens you can call reject
  reject(reason);
}, function(data, solve, reject){
	//this function will be excecuted when the workflow ends
	data.output //the result of the workflow
   	data.job //the job assigned to that workflow
   	data.config //the configuration of the workflow
   	data.input //the input of the workflow
});

Loggin

You can loggin in the worflow with mgr.logger you can use info error warn.

To require taks made by other:

fluo.task('x', require('task-r'));

How to define workflows

fluo.workflow('workflow-x', function(mgr, cfg, initialData, solve, reject) {
  
  var ouput = mgr.runTask('trasform-x', 'task-input', {config: 'config'});
  if (output == 'x') {
    mgr.runTask('process-y');
  } else {
  	mgr.runTask('process-z');
  }

});

hook

You can add a function to be excecuted when the workflow ends.

fluo.workflow('workflow-x', function(mgr, cfg, initialData, solve, reject) {
  
  var ouput = mgr.runTask('trasform-x', 'task-input', {config: 'config'});
  if (output == 'x') {
    mgr.runTask('process-y');
  } else {
  	mgr.runTask('process-z');
  }

}, function(data, solve, reject){
	//this function will be excecuted when the workflow ends
	data.output //the result of the workflow
   	data.job //the job assigned to that workflow
   	data.config //the configuration of the workflow
   	data.input //the input of the workflow
});

Loggin

You can loggin in the worflow with mgr.logger you can use info error warn.

Retry

You can retry a workflow with mgr.rety(reason, waitForMS) if you don't especifie a waitForMS the workflow will wait for retryTime * config.waitTimeBeforeRetry also keep in mind that the retry function will throw an error to stop the current job.

You can specifie the given values in the fluo config.

config = { 
  maxRetryTimes : 'Default 3'
  waitTimeBeforeRetry : 'Default 1000'
  progressiveIncreaseTimeBeforeRetry: 'Default true'
}

How to define triggers

fluo.trigger('trigger-x', function(config, trigger) {
  //You will receive a config object
  //You can call the function fire when you want to excecute the workflow
  //remember to pass the initial data to the fire function
  trigger.fire('initial data');
});

How to map a trigger to a WorkFlow

fluo.map(
	{'name':'trigger-x', 'config':config}, 
	[
		{ 'name':'workflow-x', 'config':config }
	]);

you can map multiple Workflow to a single trigger

fluo.map(
	{'name':'trigger-x', 'config':config}, 
	[
		{ 'name':'workflow-x', 'config':config },
		{ 'name':'workflow-y', 'config':config }
	]);

you can map multiple triggers to a single workflow

fluo.map(
	{'name':'trigger-x', 'config':config}, 
	[
		{ 'name':'workflow-x', 'config':config }
	]);

fluo.map(
	{'name':'trigger-y', 'config':config}, 
	[
		{ 'name':'workflow-x', 'config':config }
	]);

How to start

You can start all the triggers

fluo.start();

You can start a specific trigger os a set of triggers

fluo.start(['trigger-x', 'trigger-y']);

You can run a workflow without a trigger

fluo.run('workflow-x', 'initial data', config);

Tests

To run the test you must have mocha installed in your machine

npm install mocha -g

After that you can run mocha test --recursive in the project root scope or mocha test --recursive --watch to watch for changes in the files.

TODO

  • Config and Input schema validation.
  • Fluo import, allow an instance of fluo to import the tasks and workflows of another instance.
  • Clone the config object.
  • Add retry to the tasks
  • Add the task name inthe logs when a task log.
  • Check if a workflow or task name has been used.
  • Send a manager instance to a trigger in order to allow run an unknown workflow in the trigger.
  • Add tests to check if an exception is catched in the the runTask and in the run funciton.

How to contribute

We are following the airbnb js style guide and please follow the TDD approach or at least make the needed tests for the feature you are working on.