-
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.
/**
* Definition of Task.
*
*/
var _l = {},
Task;
_l.sys = require('sys');
/**
* Constructor of a new task.
*/
Task = exports.Task = function() {
this.framework; /* reference to the framework*/
this.name = 'your task with no name'; /* the name of the task*/
this.next; /* the reference to the next task in the chain.*/
};
/**
* Adding the TaskSequencer to Task definition, any Task that uses this object as prototype
* getting access to tha TaskSequencer.
*/
Task.prototype.TaskSequencer = require('../lib/sequencer');
/**
* 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;
/* Using TaskSequencer to take care of the task chain execution.
If executeSelf() is finished, the framework is passed on to: callNextTask().*/
this.TaskSequencer.sequenceThat(
function executeSelf() {
/* Execute the duty function of this task first,
then pass the framework object forward to the next task.
returns the framework, it may be modified by the duty() function. */
return that.duty(framework);
},
function callNextTask(err, fr) {
if (err){throw err;}
if (that.next === undefined){
/* If no next task is defined, we reached the end of the task chain.
Execute the callback (that should be called after the build finishes) instead. */
callback(fr);
}else{
/* If a next task is defined, call its run function, and pass over the framework object
and the callback, that should be called when the build is done. */
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){
_l.sys.puts("No duty() function implemented for: '" +this.name + "' !");
_l.sys.puts("Override the run() function in your tass by writing:\n yourTask.prototype.duty = function(framework,callback){ ... }");
};
··end
##The managed tasks
##Defining a task chain