2016-05-05 16:06:04 +00:00
|
|
|
import * as plugins from "./taskbuffer.plugins";
|
2016-05-15 13:28:38 +00:00
|
|
|
import {Task} from "./taskbuffer.classes.task";
|
2016-05-05 16:06:04 +00:00
|
|
|
import helpers = require("./taskbuffer.classes.helpers");
|
2016-05-04 01:44:54 +00:00
|
|
|
|
2016-05-05 17:21:01 +00:00
|
|
|
export class Taskchain extends Task {
|
|
|
|
taskArray:Task[];
|
2016-05-15 13:52:59 +00:00
|
|
|
private _oraObject:plugins.beautylog.Ora;
|
2016-05-14 21:24:11 +00:00
|
|
|
constructor(optionsArg:{
|
2016-08-02 09:09:42 +00:00
|
|
|
taskArray:Task[],
|
2016-05-15 01:16:50 +00:00
|
|
|
name?:string,
|
|
|
|
log?:boolean,
|
2016-08-02 09:09:42 +00:00
|
|
|
buffered?:boolean,
|
|
|
|
bufferMax?:number
|
2016-05-14 21:24:11 +00:00
|
|
|
}){
|
2016-08-01 11:17:15 +00:00
|
|
|
let options = plugins.lodash.merge(
|
2016-05-15 01:16:50 +00:00
|
|
|
{
|
2016-05-15 13:52:59 +00:00
|
|
|
name:"unnamed Taskchain",
|
2016-05-15 01:16:50 +00:00
|
|
|
log:false
|
|
|
|
},
|
|
|
|
optionsArg,
|
|
|
|
{
|
2016-08-02 09:09:42 +00:00
|
|
|
taskFunction: (x:any) => { // this is the function that gets executed when TaskChain is triggered
|
2017-01-19 16:26:35 +00:00
|
|
|
let done = plugins.q.defer(); // this is the starting Deferred object
|
2016-08-02 09:09:42 +00:00
|
|
|
let taskCounter = 0; // counter for iterating async over the taskArray
|
|
|
|
let iterateTasks = (x) => {
|
2016-05-15 01:16:50 +00:00
|
|
|
if(typeof this.taskArray[taskCounter] != "undefined"){
|
2016-05-15 13:52:59 +00:00
|
|
|
this._oraObject.text(this.name + " running: Task" + this.taskArray[taskCounter].name);
|
2016-08-02 09:09:42 +00:00
|
|
|
this.taskArray[taskCounter].trigger(x)
|
|
|
|
.then((x)=>{
|
2016-08-01 11:17:15 +00:00
|
|
|
plugins.beautylog.ok(this.taskArray[taskCounter].name);
|
2016-05-15 01:16:50 +00:00
|
|
|
taskCounter++;
|
2016-08-02 09:09:42 +00:00
|
|
|
iterateTasks(x);
|
2016-05-15 01:16:50 +00:00
|
|
|
});
|
|
|
|
} else {
|
2016-05-15 13:52:59 +00:00
|
|
|
this._oraObject.endOk("Taskchain \"" + this.name + "\" completed successfully");
|
2016-08-02 09:09:42 +00:00
|
|
|
done.resolve(x);
|
2016-05-15 01:16:50 +00:00
|
|
|
}
|
|
|
|
};
|
2016-08-02 09:09:42 +00:00
|
|
|
iterateTasks(x);
|
2016-05-15 01:16:50 +00:00
|
|
|
return done.promise;
|
|
|
|
}
|
2016-05-05 16:06:04 +00:00
|
|
|
}
|
2016-05-15 01:16:50 +00:00
|
|
|
);
|
2016-05-14 21:24:11 +00:00
|
|
|
super(options);
|
|
|
|
this.taskArray = optionsArg.taskArray;
|
2016-05-15 01:16:50 +00:00
|
|
|
this._oraObject = new plugins.beautylog.Ora("Taskchain idle","blue");
|
2016-08-01 11:17:15 +00:00
|
|
|
if(optionsArg.log === true){
|
|
|
|
this._oraObject.start();
|
|
|
|
};
|
2016-05-04 01:44:54 +00:00
|
|
|
}
|
2016-05-05 17:21:01 +00:00
|
|
|
addTask(taskArg:Task){
|
2016-05-05 16:06:04 +00:00
|
|
|
this.taskArray.push(taskArg);
|
|
|
|
};
|
2016-05-05 17:21:01 +00:00
|
|
|
removeTask(taskArg:Task){
|
2016-05-05 16:06:04 +00:00
|
|
|
//TODO
|
|
|
|
};
|
|
|
|
shiftTask(){
|
|
|
|
|
|
|
|
};
|
2016-05-15 13:28:38 +00:00
|
|
|
};
|