-
Notifications
You must be signed in to change notification settings - Fork 28
Task chain
##Introduction
the task (or tasks) chain is a hook up line of actions that should be executed in the files of a framework. Each task takes the input from the previous task, do some possible manipulations on the files and pass the result on to the next task in the chain. The tasks can be combined to match the demands of the concrete building problem. A developer can specify the sequence of the tasks and also implement new ones.
This diagram shows the primary steps to build and attache a chain of tasks to a framework, included here are the involved Espresso components.
##Task definition
Each concrete task uses the Task prototype. The prototype defines the functions and properties that every task should have, to work in a task chain. A shortened overview of the Task prototype is shown here:
Task = exports.Task = function() {
this.framework;
this.name;
this.next;
};
[...]
/**
* The run function, defined here for any task.
* @param framework the framework, this task is working with
* @param callback the function, that should be called after the all tasks finished there job.
*/
Task.prototype.run = function(framework,callback){
var that = this;
this.TaskSequencer.sequenceThat(
function executeSelf() {
return that.duty(framework);
},
function callNextTask(err, fr) {
if (err){throw err;}
if (that.next === undefined){
callback(fr);
}else{
that.next.run(fr,callback);
}
}
);
};
/**
* This function should be overridden by any Task implementation.
* The duty() function contains the implementation of the action, provided by this task.
*
* @param framework the framework, this task is working with
* @param callback the function, that should be called after the all tasks finished there job.
*/
Task.prototype.duty = function(framework,callback){
// concrete tasks code goes here.
};
The important functions are: run()
which shall not be touched by a concrete task implementation using this prototype and duty()
. The run()
function implements the execution of the task itself, and then call the next task in the chain. The action of the task is implemented in the duty()
function, and is overridden by any concrete task that uses this prototype.
Here is a example of a concrete task implementation. Note: the using of the Task prototype by first: referencing the prototype 'Task = require('./Task').Task;' and then using it: 'T1.prototype = new Task;'.
var _l = {},
T1,
Task = require('./Task').Task;
_l.sys = require('sys');
T1 = exports.T1 = function() {
/* Properties */
this.name = 'T1';
};
/**
* Using Task prototype
*/
T1.prototype = new Task;
/**
* The duty of this task. Overridden from prototype
*/
T1.prototype.duty = function(framework) {
// duty of this tasks.
return framework;
};
##The managed tasks
##Defining a task chain