update taskbuffer and add gitlab ci
This commit is contained in:
parent
8a414b9a7d
commit
24e96926e3
36
.gitlab-ci.yml
Normal file
36
.gitlab-ci.yml
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
image: hosttoday/ht-docker-node:npmts
|
||||||
|
|
||||||
|
stages:
|
||||||
|
- test
|
||||||
|
- release
|
||||||
|
|
||||||
|
testLEGACY:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci test legacy
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
testLTS:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci test lts
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
testSTABLE:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci test stable
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
release:
|
||||||
|
stage: release
|
||||||
|
environment: npmjs-com_registry
|
||||||
|
script:
|
||||||
|
- npmci publish
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
tags:
|
||||||
|
- docker
|
11
.travis.yml
11
.travis.yml
@ -1,11 +0,0 @@
|
|||||||
language: node_js
|
|
||||||
node_js:
|
|
||||||
- stable
|
|
||||||
deploy:
|
|
||||||
provider: npm
|
|
||||||
email: npm@lossless.digital
|
|
||||||
api_key:
|
|
||||||
secure: NejErc2+ohEEH8DecYcx6/2oSdEQQBRzlOwTMxQBftHdIkvziwOcCerqCJtrXuzalqAofVCcVisunWIXZmxfIBGV6mJVauCIp5KzH4JUhYzLym33p9MSphjlPNfsI6nKkW0LAgOMjkJGuHLqU3oskvBqYyh8m3NuCna5mNwm8lo5WGckzHSwdsmhnb839WhlZbmQc6M6WW6Ir7bbxX9ZOmNUYUWH6VdXfPBxoXN3nO21pXKt7Zg8/nU7IkF+VEUVfYNlR3xUiocWemuBFxjtsfoliQ/y/oGL7ccQ7OeE4PxSu+xNUpYYVipkQcRtyWDKCwJp4R2DNTj/ikOHH+BEFOBDG8qYxwf37Ju0jFybzslAEJLy5gl4bFjiZNA8ldUXY5ubJb56iZTNSbMU0lmXw+qKvIoyVY/1JAE5lzFGVA6nDdiUGAEOg/ajzAC3gjFU2QS2Wvncz3dky0k/2INBVUwmmAvAMazl5XkvHtQ3Wzb+Fc8TXWflqBDF0okySoJzlY13pm/OtOHipiqEyUCnqaUUwJtLIb6tHOPzxZKlWLCem7y84cDlxQSbLVItbArOJFHdr66sp/U/FqYAtWeLdbkhjCENFwzR9kYtEyEl+QWLTckO1/lVF4xJLh6drfhQ66CwF5bfqr5xIS08mnKuYBfJOA4/wV4bQFPhtYm7Oi8=
|
|
||||||
on:
|
|
||||||
tags: true
|
|
||||||
repo: pushrocks/taskbuffer
|
|
5
dist/taskbuffer.classes.helpers.d.ts
vendored
5
dist/taskbuffer.classes.helpers.d.ts
vendored
@ -1,11 +1,10 @@
|
|||||||
/// <reference types="q" />
|
/// <reference types="q" />
|
||||||
import plugins = require("./taskbuffer.plugins");
|
import plugins = require("./taskbuffer.plugins");
|
||||||
import { Task } from "./taskbuffer.classes.task";
|
import { Task, ITaskFunction } from "./taskbuffer.classes.task";
|
||||||
export declare let emptyTaskFunction: () => plugins.Q.Promise<{}>;
|
export declare let emptyTaskFunction: ITaskFunction;
|
||||||
export declare let isTask: (taskArg: any) => boolean;
|
export declare let isTask: (taskArg: any) => boolean;
|
||||||
export declare let isTaskTouched: (taskArg: Task, touchedTasksArray: Task[]) => boolean;
|
export declare let isTaskTouched: (taskArg: Task, touchedTasksArray: Task[]) => boolean;
|
||||||
export declare let runTask: (taskArg: Task, optionsArg?: {
|
export declare let runTask: (taskArg: Task, optionsArg?: {
|
||||||
touchedTasksArray: Task[];
|
touchedTasksArray: Task[];
|
||||||
}) => plugins.Q.Promise<{}>;
|
}) => plugins.Q.Promise<{}>;
|
||||||
export declare let runBufferedTask: (taskArg: Task) => void;
|
export declare let runBufferedTask: (taskArg: Task) => void;
|
||||||
export declare let updateTaskStatus: (taskArg: any, statusArg: string) => void;
|
|
||||||
|
24
dist/taskbuffer.classes.helpers.js
vendored
24
dist/taskbuffer.classes.helpers.js
vendored
@ -26,8 +26,8 @@ exports.isTaskTouched = (taskArg, touchedTasksArray) => {
|
|||||||
};
|
};
|
||||||
exports.runTask = function (taskArg, optionsArg = { touchedTasksArray: [] }) {
|
exports.runTask = function (taskArg, optionsArg = { touchedTasksArray: [] }) {
|
||||||
let done = plugins.Q.defer();
|
let done = plugins.Q.defer();
|
||||||
exports.updateTaskStatus(taskArg, "running");
|
taskArg.running = true;
|
||||||
done.promise.then(function () { exports.updateTaskStatus(taskArg, "idle"); });
|
done.promise.then(function () { taskArg.running = false; });
|
||||||
let localDeferred = plugins.Q.defer();
|
let localDeferred = plugins.Q.defer();
|
||||||
let touchedTasksArray;
|
let touchedTasksArray;
|
||||||
if (optionsArg.touchedTasksArray) {
|
if (optionsArg.touchedTasksArray) {
|
||||||
@ -70,24 +70,14 @@ exports.runTask = function (taskArg, optionsArg = { touchedTasksArray: [] }) {
|
|||||||
exports.runBufferedTask = (taskArg) => {
|
exports.runBufferedTask = (taskArg) => {
|
||||||
let recursiveBufferRunner = () => {
|
let recursiveBufferRunner = () => {
|
||||||
if (taskArg.bufferCounter > 0) {
|
if (taskArg.bufferCounter > 0) {
|
||||||
|
taskArg.runningBuffered = true;
|
||||||
taskArg.bufferCounter--;
|
taskArg.bufferCounter--;
|
||||||
exports.runTask(taskArg)
|
exports.runTask(taskArg)
|
||||||
.then(recursiveBufferRunner);
|
.then(recursiveBufferRunner);
|
||||||
}
|
}
|
||||||
};
|
else {
|
||||||
};
|
taskArg.runningBuffered = false;
|
||||||
exports.updateTaskStatus = (taskArg, statusArg) => {
|
|
||||||
switch (statusArg) {
|
|
||||||
case "running":
|
|
||||||
taskArg.running = true;
|
|
||||||
taskArg.idle = false;
|
|
||||||
break;
|
|
||||||
case "idle":
|
|
||||||
taskArg.running = false;
|
|
||||||
taskArg.idle = true;
|
|
||||||
break;
|
|
||||||
default:
|
|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UN4QixDQUFDLENBQUM7QUFFUyx1QkFBZSxHQUFHLENBQUMsT0FBWTtJQUN0QyxJQUFJLHFCQUFxQixHQUFHO1FBQ3hCLEVBQUUsQ0FBQSxDQUFDLE9BQU8sQ0FBQyxhQUFhLEdBQUcsQ0FBQyxDQUFDLENBQUEsQ0FBQztZQUMxQixPQUFPLENBQUMsZUFBZSxHQUFHLElBQUksQ0FBQztZQUMvQixPQUFPLENBQUMsYUFBYSxFQUFFLENBQUM7WUFDeEIsZUFBTyxDQUFDLE9BQU8sQ0FBQztpQkFDWCxJQUFJLENBQUMscUJBQXFCLENBQUMsQ0FBQztRQUNyQyxDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDSixPQUFPLENBQUMsZUFBZSxHQUFHLEtBQUssQ0FBQztRQUNwQyxDQUFDO0lBQ0wsQ0FBQyxDQUFBO0FBQ0wsQ0FBQyxDQUFDIn0=
|
15
dist/taskbuffer.classes.task.d.ts
vendored
15
dist/taskbuffer.classes.task.d.ts
vendored
@ -1,9 +1,13 @@
|
|||||||
/// <reference types="q" />
|
/// <reference types="q" />
|
||||||
import * as plugins from "./taskbuffer.plugins";
|
import * as plugins from "./taskbuffer.plugins";
|
||||||
|
export interface ITaskFunction {
|
||||||
|
(): PromiseLike<any>;
|
||||||
|
}
|
||||||
export declare class Task {
|
export declare class Task {
|
||||||
name: string;
|
name: string;
|
||||||
task: any;
|
task: any;
|
||||||
running: boolean;
|
running: boolean;
|
||||||
|
runningBuffered: boolean;
|
||||||
idle: boolean;
|
idle: boolean;
|
||||||
buffered: boolean;
|
buffered: boolean;
|
||||||
bufferCounter: number;
|
bufferCounter: number;
|
||||||
@ -13,15 +17,24 @@ export declare class Task {
|
|||||||
preTask: Task;
|
preTask: Task;
|
||||||
afterTask: Task;
|
afterTask: Task;
|
||||||
constructor(optionsArg: {
|
constructor(optionsArg: {
|
||||||
taskFunction: any;
|
taskFunction: ITaskFunction;
|
||||||
preTask?: Task;
|
preTask?: Task;
|
||||||
afterTask?: Task;
|
afterTask?: Task;
|
||||||
buffered?: boolean;
|
buffered?: boolean;
|
||||||
bufferMax?: number;
|
bufferMax?: number;
|
||||||
name?: string;
|
name?: string;
|
||||||
});
|
});
|
||||||
|
/**
|
||||||
|
* trigger the task. Will trigger buffered if this.buffered is true
|
||||||
|
*/
|
||||||
trigger(): plugins.Q.Promise<{}>;
|
trigger(): plugins.Q.Promise<{}>;
|
||||||
|
/**
|
||||||
|
* trigger task unbuffered.
|
||||||
|
*/
|
||||||
triggerUnBuffered(): plugins.Q.Promise<{}>;
|
triggerUnBuffered(): plugins.Q.Promise<{}>;
|
||||||
|
/**
|
||||||
|
* trigger task buffered.
|
||||||
|
*/
|
||||||
triggerBuffered(): plugins.Q.Promise<{}>;
|
triggerBuffered(): plugins.Q.Promise<{}>;
|
||||||
state: string;
|
state: string;
|
||||||
}
|
}
|
||||||
|
26
dist/taskbuffer.classes.task.js
vendored
26
dist/taskbuffer.classes.task.js
vendored
@ -3,19 +3,25 @@ const plugins = require("./taskbuffer.plugins");
|
|||||||
const helpers = require("./taskbuffer.classes.helpers");
|
const helpers = require("./taskbuffer.classes.helpers");
|
||||||
class Task {
|
class Task {
|
||||||
constructor(optionsArg) {
|
constructor(optionsArg) {
|
||||||
if (!optionsArg) {
|
this.running = false;
|
||||||
optionsArg = { taskFunction: function () { } };
|
this.runningBuffered = false;
|
||||||
}
|
this.idle = true;
|
||||||
|
this.buffered = false;
|
||||||
|
this.bufferMax = 1;
|
||||||
|
this._counterTriggerAbsolute = 0;
|
||||||
var options = optionsArg;
|
var options = optionsArg;
|
||||||
this.task = optionsArg.taskFunction;
|
this.task = optionsArg.taskFunction;
|
||||||
this.preTask = options.preTask;
|
this.preTask = options.preTask;
|
||||||
this.afterTask = options.afterTask;
|
this.afterTask = options.afterTask;
|
||||||
this.running = false;
|
this.running = false;
|
||||||
this.idle = true;
|
this.idle = !this.running && !this.runningBuffered;
|
||||||
this.buffered = options.buffered;
|
this.buffered = options.buffered;
|
||||||
this.bufferMax = options.bufferMax;
|
this.bufferMax = options.bufferMax;
|
||||||
this.name = options.name;
|
this.name = options.name;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* trigger the task. Will trigger buffered if this.buffered is true
|
||||||
|
*/
|
||||||
trigger() {
|
trigger() {
|
||||||
let done = plugins.Q.defer();
|
let done = plugins.Q.defer();
|
||||||
if (this.buffered) {
|
if (this.buffered) {
|
||||||
@ -30,15 +36,25 @@ class Task {
|
|||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
/**
|
||||||
|
* trigger task unbuffered.
|
||||||
|
*/
|
||||||
triggerUnBuffered() {
|
triggerUnBuffered() {
|
||||||
return helpers.runTask(this);
|
return helpers.runTask(this);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* trigger task buffered.
|
||||||
|
*/
|
||||||
triggerBuffered() {
|
triggerBuffered() {
|
||||||
var done = plugins.Q.defer();
|
var done = plugins.Q.defer();
|
||||||
if (!(this.bufferCounter >= this.bufferMax)) {
|
if (!(this.bufferCounter >= this.bufferMax)) {
|
||||||
this.bufferCounter++;
|
this.bufferCounter++;
|
||||||
}
|
}
|
||||||
|
;
|
||||||
|
if (!this.runningBuffered) {
|
||||||
helpers.runBufferedTask(this);
|
helpers.runBufferedTask(this);
|
||||||
|
}
|
||||||
|
;
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
get state() {
|
get state() {
|
||||||
@ -54,4 +70,4 @@ class Task {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.Task = Task;
|
exports.Task = Task;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFza2J1ZmZlci5jbGFzc2VzLnRhc2suanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy90YXNrYnVmZmVyLmNsYXNzZXMudGFzay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjo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QUEsQ0FBQyxDQUFDLElBQUksQ0FBQyxlQUFlLENBQUMsQ0FBQSxDQUFDO1lBQ3RCLE9BQU8sQ0FBQyxlQUFlLENBQUMsSUFBSSxDQUFDLENBQUM7UUFDbEMsQ0FBQztRQUFBLENBQUM7UUFDRixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQztJQUN4QixDQUFDO0lBRUQsSUFBSSxLQUFLO1FBQ0wsTUFBTSxDQUFDLElBQUksQ0FBQyxNQUFNLENBQUM7SUFDdkIsQ0FBQztJQUNELElBQUksS0FBSyxDQUFDLFFBQWU7UUFDckIsRUFBRSxDQUFDLENBQUMsUUFBUSxJQUFJLFFBQVEsQ0FBQyxDQUFBLENBQUM7WUFDdEIsSUFBSSxDQUFDLE1BQU0sR0FBRyxRQUFRLENBQUM7UUFDM0IsQ0FBQztRQUFDLElBQUksQ0FBQyxDQUFDO1lBQ0osT0FBTyxDQUFDLFNBQVMsQ0FBQyxLQUFLLENBQUMsYUFBYSxHQUFHLFFBQVEsQ0FBQyxJQUFJLEdBQUcsbUJBQW1CLENBQUMsQ0FBQztRQUNqRixDQUFDO0lBQ0wsQ0FBQztBQUNMLENBQUM7QUFoRlksWUFBSSxPQWdGaEIsQ0FBQSJ9
|
10
dist/taskbuffer.classes.taskchain.js
vendored
10
dist/taskbuffer.classes.taskchain.js
vendored
@ -4,7 +4,7 @@ const taskbuffer_classes_task_1 = require("./taskbuffer.classes.task");
|
|||||||
const helpers = require("./taskbuffer.classes.helpers");
|
const helpers = require("./taskbuffer.classes.helpers");
|
||||||
class Taskchain extends taskbuffer_classes_task_1.Task {
|
class Taskchain extends taskbuffer_classes_task_1.Task {
|
||||||
constructor(optionsArg) {
|
constructor(optionsArg) {
|
||||||
let options = plugins.lodash.assign({
|
let options = plugins.lodash.merge({
|
||||||
name: "unnamed Taskchain",
|
name: "unnamed Taskchain",
|
||||||
log: false
|
log: false
|
||||||
}, optionsArg, {
|
}, optionsArg, {
|
||||||
@ -16,7 +16,7 @@ class Taskchain extends taskbuffer_classes_task_1.Task {
|
|||||||
this._oraObject.text(this.name + " running: Task" + this.taskArray[taskCounter].name);
|
this._oraObject.text(this.name + " running: Task" + this.taskArray[taskCounter].name);
|
||||||
this.taskArray[taskCounter].trigger()
|
this.taskArray[taskCounter].trigger()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this._oraObject.log(this.taskArray[taskCounter].name, "ok");
|
plugins.beautylog.ok(this.taskArray[taskCounter].name);
|
||||||
taskCounter++;
|
taskCounter++;
|
||||||
iterateTasks();
|
iterateTasks();
|
||||||
});
|
});
|
||||||
@ -33,6 +33,10 @@ class Taskchain extends taskbuffer_classes_task_1.Task {
|
|||||||
super(options);
|
super(options);
|
||||||
this.taskArray = optionsArg.taskArray;
|
this.taskArray = optionsArg.taskArray;
|
||||||
this._oraObject = new plugins.beautylog.Ora("Taskchain idle", "blue");
|
this._oraObject = new plugins.beautylog.Ora("Taskchain idle", "blue");
|
||||||
|
if (optionsArg.log === true) {
|
||||||
|
this._oraObject.start();
|
||||||
|
}
|
||||||
|
;
|
||||||
}
|
}
|
||||||
addTask(taskArg) {
|
addTask(taskArg) {
|
||||||
this.taskArray.push(taskArg);
|
this.taskArray.push(taskArg);
|
||||||
@ -52,4 +56,4 @@ class Taskchain extends taskbuffer_classes_task_1.Task {
|
|||||||
}
|
}
|
||||||
exports.Taskchain = Taskchain;
|
exports.Taskchain = Taskchain;
|
||||||
;
|
;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFza2J1ZmZlci5jbGFzc2VzLnRhc2tjaGFpbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3Rhc2tidWZmZXIuY2xhc3Nlcy50YXNrY2hhaW4udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHNCQUFzQixDQUFDLENBQUE7QUFDaEQsMENBQW1CL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FBQztJQUNqQyxDQUFDOztJQUNELFVBQVUsQ0FBQyxPQUFZO1FBQ25CLE1BQU07SUFDVixDQUFDOztJQUNELFNBQVM7SUFFVCxDQUFDOztJQUNELE9BQU87UUFDSCxJQUFJLENBQUMsVUFBVSxDQUFDLEtBQUssQ0FBQyxJQUFJLENBQUMsSUFBSSxHQUFHLGFBQWEsQ0FBQyxDQUFDO1FBQ2pELE1BQU0sQ0FBQyxPQUFPLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO0lBQ2pDLENBQUM7QUFDTCxDQUFDO0FBekRZLGlCQUFTLFlBeURyQixDQUFBO0FBQUEsQ0FBQyJ9
|
7
dist/taskbuffer.classes.taskparallel.js
vendored
7
dist/taskbuffer.classes.taskparallel.js
vendored
@ -3,10 +3,10 @@ const plugins = require("./taskbuffer.plugins");
|
|||||||
const taskbuffer_classes_task_1 = require("./taskbuffer.classes.task");
|
const taskbuffer_classes_task_1 = require("./taskbuffer.classes.task");
|
||||||
class Taskparallel extends taskbuffer_classes_task_1.Task {
|
class Taskparallel extends taskbuffer_classes_task_1.Task {
|
||||||
constructor(optionsArg) {
|
constructor(optionsArg) {
|
||||||
let options = plugins.lodash.assign(optionsArg, {
|
let options = plugins.lodash.merge(optionsArg, {
|
||||||
taskFunction: () => {
|
taskFunction: () => {
|
||||||
let done = plugins.Q.defer();
|
let done = plugins.Q.defer();
|
||||||
let promiseArray; // stores promises of all tasks, since they run in parallel
|
let promiseArray = []; // stores promises of all tasks, since they run in parallel
|
||||||
this.taskArray.forEach(function (taskArg) {
|
this.taskArray.forEach(function (taskArg) {
|
||||||
promiseArray.push(taskArg.trigger());
|
promiseArray.push(taskArg.trigger());
|
||||||
});
|
});
|
||||||
@ -16,7 +16,8 @@ class Taskparallel extends taskbuffer_classes_task_1.Task {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
super(options);
|
super(options);
|
||||||
|
this.taskArray = optionsArg.taskArray;
|
||||||
}
|
}
|
||||||
}
|
}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FDLENBQUM7UUFDZixJQUFJLENBQUMsU0FBUyxHQUFHLFVBQVUsQ0FBQyxTQUFTLENBQUM7SUFDMUMsQ0FBQztBQUNMLENBQUM7QUF2Qlksb0JBQVksZUF1QnhCLENBQUEifQ==
|
@ -28,13 +28,13 @@
|
|||||||
"@types/q": "^0.0.27",
|
"@types/q": "^0.0.27",
|
||||||
"beautylog": "^5.0.18",
|
"beautylog": "^5.0.18",
|
||||||
"lodash": "^4.14.1",
|
"lodash": "^4.14.1",
|
||||||
"projectinfo": "1.0.3",
|
|
||||||
"q": "^1.4.1",
|
"q": "^1.4.1",
|
||||||
"rxjs": "^5.0.0-beta.10",
|
"rxjs": "^5.0.0-beta.10",
|
||||||
"typings-global": "^1.0.6"
|
"typings-global": "^1.0.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"npmts-g": "^5.2.8",
|
"npmts-g": "^5.2.8",
|
||||||
"should": "^10.0.0"
|
"should": "^10.0.0",
|
||||||
|
"typings-test": "^1.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
test/test.d.ts
vendored
1
test/test.d.ts
vendored
@ -0,0 +1 @@
|
|||||||
|
import "typings-test";
|
64
test/test.js
64
test/test.js
File diff suppressed because one or more lines are too long
63
test/test.ts
63
test/test.ts
@ -1,21 +1,22 @@
|
|||||||
/// <reference path="../ts/typings/main.d.ts" />
|
import "typings-test";
|
||||||
import taskbuffer = require("../dist/index");
|
import taskbuffer = require("../dist/index");
|
||||||
let should = require("should");
|
let should = require("should");
|
||||||
let plugins = {
|
import q = require("q")
|
||||||
q: require("q")
|
|
||||||
}
|
|
||||||
|
|
||||||
// setup some testData to work with
|
// setup some testData to work with
|
||||||
let testTask:taskbuffer.Task;
|
let testTask:taskbuffer.Task;
|
||||||
let testTaskFunction = function(){
|
let testTaskFunction = function(){
|
||||||
let done = plugins.q.defer();
|
let done = q.defer();
|
||||||
console.log("main function executed!")
|
console.log("main function executed!")
|
||||||
done.resolve();
|
done.resolve();
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
let testPreTask = new taskbuffer.Task({
|
let testPreTask = new taskbuffer.Task({
|
||||||
taskFunction:function(){
|
taskFunction:function(){
|
||||||
|
let done = q.defer();
|
||||||
console.log("preTask executed");
|
console.log("preTask executed");
|
||||||
|
done.resolve();
|
||||||
|
return done.promise;
|
||||||
},
|
},
|
||||||
preTask:testTask
|
preTask:testTask
|
||||||
});
|
});
|
||||||
@ -56,7 +57,7 @@ describe("taskbuffer",function(){
|
|||||||
new taskbuffer.Task({
|
new taskbuffer.Task({
|
||||||
name:"task1",
|
name:"task1",
|
||||||
taskFunction:function(){
|
taskFunction:function(){
|
||||||
let done = plugins.q.defer();
|
let done = q.defer();
|
||||||
setTimeout(done.resolve,2000);
|
setTimeout(done.resolve,2000);
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
@ -64,7 +65,7 @@ describe("taskbuffer",function(){
|
|||||||
new taskbuffer.Task({
|
new taskbuffer.Task({
|
||||||
name:"task2",
|
name:"task2",
|
||||||
taskFunction: function(){
|
taskFunction: function(){
|
||||||
let done = plugins.q.defer();
|
let done = q.defer();
|
||||||
setTimeout(done.resolve,2000);
|
setTimeout(done.resolve,2000);
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
@ -77,7 +78,53 @@ describe("taskbuffer",function(){
|
|||||||
taskArray:testTaskArray
|
taskArray:testTaskArray
|
||||||
});
|
});
|
||||||
testTaskchain.trigger().then(done);
|
testTaskchain.trigger().then(done);
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe("taskparallel",function(){
|
||||||
|
let task1 = new taskbuffer.Task({
|
||||||
|
name:"Task 1",
|
||||||
|
taskFunction: () => {
|
||||||
|
let done = q.defer();
|
||||||
|
console.log("Task1 started");
|
||||||
|
setTimeout(() => {
|
||||||
|
console.log("Task1 executed");
|
||||||
|
done.resolve();
|
||||||
|
},5000)
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let task2 = new taskbuffer.Task({
|
||||||
|
name:"Task 1",
|
||||||
|
taskFunction: () => {
|
||||||
|
let done = q.defer();
|
||||||
|
console.log("Task2 started");
|
||||||
|
setTimeout(() => {
|
||||||
|
console.log("Task2 executed");
|
||||||
|
done.resolve();
|
||||||
|
},5000)
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let task3 = new taskbuffer.Task({
|
||||||
|
name:"Task 3",
|
||||||
|
taskFunction: () => {
|
||||||
|
let done = q.defer();
|
||||||
|
console.log("Task3 started");
|
||||||
|
setTimeout(() => {
|
||||||
|
console.log("Task3 executed");
|
||||||
|
done.resolve();
|
||||||
|
},5000)
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
it("should run in Parallel",function(done){
|
||||||
|
this.timeout("7000");
|
||||||
|
let testTaskparallel = new taskbuffer.Taskparallel({
|
||||||
|
taskArray:[task1,task2,task3]
|
||||||
|
});
|
||||||
|
testTaskparallel.trigger().then(() => {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
})
|
||||||
});
|
});
|
@ -1,7 +1,7 @@
|
|||||||
import plugins = require("./taskbuffer.plugins");
|
import plugins = require("./taskbuffer.plugins");
|
||||||
import {Task} from "./taskbuffer.classes.task";
|
import {Task,ITaskFunction} from "./taskbuffer.classes.task";
|
||||||
|
|
||||||
export let emptyTaskFunction = function(){
|
export let emptyTaskFunction:ITaskFunction = function(){
|
||||||
let done = plugins.Q.defer();
|
let done = plugins.Q.defer();
|
||||||
done.resolve();
|
done.resolve();
|
||||||
return done.promise;
|
return done.promise;
|
||||||
@ -31,8 +31,8 @@ export let isTaskTouched = (taskArg:Task, touchedTasksArray:Task[]):boolean => {
|
|||||||
|
|
||||||
export let runTask = function(taskArg:Task,optionsArg:{touchedTasksArray:Task[]} = {touchedTasksArray:[]}){
|
export let runTask = function(taskArg:Task,optionsArg:{touchedTasksArray:Task[]} = {touchedTasksArray:[]}){
|
||||||
let done = plugins.Q.defer();
|
let done = plugins.Q.defer();
|
||||||
updateTaskStatus(taskArg,"running");
|
taskArg.running = true;
|
||||||
done.promise.then(function(){updateTaskStatus(taskArg,"idle")})
|
done.promise.then(function(){taskArg.running = false});
|
||||||
let localDeferred = plugins.Q.defer();
|
let localDeferred = plugins.Q.defer();
|
||||||
let touchedTasksArray:Task[];
|
let touchedTasksArray:Task[];
|
||||||
if(optionsArg.touchedTasksArray){
|
if(optionsArg.touchedTasksArray){
|
||||||
@ -73,24 +73,12 @@ export let runTask = function(taskArg:Task,optionsArg:{touchedTasksArray:Task[]}
|
|||||||
export let runBufferedTask = (taskArg:Task) => {
|
export let runBufferedTask = (taskArg:Task) => {
|
||||||
let recursiveBufferRunner = () => {
|
let recursiveBufferRunner = () => {
|
||||||
if(taskArg.bufferCounter > 0){
|
if(taskArg.bufferCounter > 0){
|
||||||
|
taskArg.runningBuffered = true;
|
||||||
taskArg.bufferCounter--;
|
taskArg.bufferCounter--;
|
||||||
runTask(taskArg)
|
runTask(taskArg)
|
||||||
.then(recursiveBufferRunner);
|
.then(recursiveBufferRunner);
|
||||||
|
} else {
|
||||||
|
taskArg.runningBuffered = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
export let updateTaskStatus = (taskArg,statusArg:string) => {
|
|
||||||
switch (statusArg) {
|
|
||||||
case "running":
|
|
||||||
taskArg.running = true;
|
|
||||||
taskArg.idle = false;
|
|
||||||
break;
|
|
||||||
case "idle":
|
|
||||||
taskArg.running = false;
|
|
||||||
taskArg.idle = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Error("status not recognised");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +1,47 @@
|
|||||||
import * as plugins from "./taskbuffer.plugins"
|
import * as plugins from "./taskbuffer.plugins"
|
||||||
import * as helpers from "./taskbuffer.classes.helpers"
|
import * as helpers from "./taskbuffer.classes.helpers"
|
||||||
|
|
||||||
|
|
||||||
|
export interface ITaskFunction {
|
||||||
|
():PromiseLike<any>;
|
||||||
|
}
|
||||||
|
|
||||||
export class Task {
|
export class Task {
|
||||||
name:string;
|
name:string;
|
||||||
task:any;
|
task:any;
|
||||||
running:boolean;
|
running:boolean = false;
|
||||||
idle:boolean;
|
runningBuffered:boolean = false;
|
||||||
buffered:boolean;
|
idle:boolean = true;
|
||||||
|
buffered:boolean = false;
|
||||||
bufferCounter:number;
|
bufferCounter:number;
|
||||||
bufferMax:number;
|
bufferMax:number = 1;
|
||||||
private _counterTriggerAbsolute:number;
|
private _counterTriggerAbsolute:number = 0;
|
||||||
private _state:string;
|
private _state:string;
|
||||||
preTask:Task;
|
preTask:Task;
|
||||||
afterTask:Task;
|
afterTask:Task;
|
||||||
|
|
||||||
constructor(optionsArg:{
|
constructor(optionsArg:{
|
||||||
taskFunction:any,
|
taskFunction:ITaskFunction,
|
||||||
preTask?:Task,
|
preTask?:Task,
|
||||||
afterTask?:Task,
|
afterTask?:Task,
|
||||||
buffered?:boolean,
|
buffered?:boolean,
|
||||||
bufferMax?:number,
|
bufferMax?:number,
|
||||||
name?:string
|
name?:string
|
||||||
}){
|
}){
|
||||||
if (!optionsArg){optionsArg = {taskFunction:function(){}}}
|
|
||||||
var options = optionsArg;
|
var options = optionsArg;
|
||||||
this.task = optionsArg.taskFunction;
|
this.task = optionsArg.taskFunction;
|
||||||
this.preTask = options.preTask;
|
this.preTask = options.preTask;
|
||||||
this.afterTask = options.afterTask;
|
this.afterTask = options.afterTask;
|
||||||
this.running = false;
|
this.running = false;
|
||||||
this.idle = true;
|
this.idle = !this.running && !this.runningBuffered;
|
||||||
this.buffered = options.buffered;
|
this.buffered = options.buffered;
|
||||||
this.bufferMax = options.bufferMax;
|
this.bufferMax = options.bufferMax;
|
||||||
this.name = options.name;
|
this.name = options.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* trigger the task. Will trigger buffered if this.buffered is true
|
||||||
|
*/
|
||||||
trigger(){
|
trigger(){
|
||||||
let done = plugins.Q.defer();
|
let done = plugins.Q.defer();
|
||||||
if(this.buffered) {
|
if(this.buffered) {
|
||||||
@ -46,15 +54,25 @@ export class Task {
|
|||||||
};
|
};
|
||||||
return done.promise;
|
return done.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* trigger task unbuffered.
|
||||||
|
*/
|
||||||
triggerUnBuffered(){
|
triggerUnBuffered(){
|
||||||
return helpers.runTask(this);
|
return helpers.runTask(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* trigger task buffered.
|
||||||
|
*/
|
||||||
triggerBuffered(){
|
triggerBuffered(){
|
||||||
var done = plugins.Q.defer();
|
var done = plugins.Q.defer();
|
||||||
if(!(this.bufferCounter >= this.bufferMax)){
|
if(!(this.bufferCounter >= this.bufferMax)){
|
||||||
this.bufferCounter++
|
this.bufferCounter++
|
||||||
}
|
};
|
||||||
|
if(!this.runningBuffered){
|
||||||
helpers.runBufferedTask(this);
|
helpers.runBufferedTask(this);
|
||||||
|
};
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ export class Taskchain extends Task {
|
|||||||
log?:boolean,
|
log?:boolean,
|
||||||
taskArray:Task[]
|
taskArray:Task[]
|
||||||
}){
|
}){
|
||||||
let options = plugins.lodash.assign(
|
let options = plugins.lodash.merge(
|
||||||
{
|
{
|
||||||
name:"unnamed Taskchain",
|
name:"unnamed Taskchain",
|
||||||
log:false
|
log:false
|
||||||
@ -25,7 +25,7 @@ export class Taskchain extends Task {
|
|||||||
this._oraObject.text(this.name + " running: Task" + this.taskArray[taskCounter].name);
|
this._oraObject.text(this.name + " running: Task" + this.taskArray[taskCounter].name);
|
||||||
this.taskArray[taskCounter].trigger()
|
this.taskArray[taskCounter].trigger()
|
||||||
.then(()=>{
|
.then(()=>{
|
||||||
this._oraObject.log(this.taskArray[taskCounter].name,"ok");
|
plugins.beautylog.ok(this.taskArray[taskCounter].name);
|
||||||
taskCounter++;
|
taskCounter++;
|
||||||
iterateTasks();
|
iterateTasks();
|
||||||
});
|
});
|
||||||
@ -42,6 +42,9 @@ export class Taskchain extends Task {
|
|||||||
super(options);
|
super(options);
|
||||||
this.taskArray = optionsArg.taskArray;
|
this.taskArray = optionsArg.taskArray;
|
||||||
this._oraObject = new plugins.beautylog.Ora("Taskchain idle","blue");
|
this._oraObject = new plugins.beautylog.Ora("Taskchain idle","blue");
|
||||||
|
if(optionsArg.log === true){
|
||||||
|
this._oraObject.start();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
addTask(taskArg:Task){
|
addTask(taskArg:Task){
|
||||||
this.taskArray.push(taskArg);
|
this.taskArray.push(taskArg);
|
||||||
|
@ -7,13 +7,13 @@ export class Taskparallel extends Task {
|
|||||||
constructor(optionsArg: {
|
constructor(optionsArg: {
|
||||||
taskArray: Task[]
|
taskArray: Task[]
|
||||||
}){
|
}){
|
||||||
let options = plugins.lodash.assign(
|
let options = plugins.lodash.merge(
|
||||||
optionsArg,
|
optionsArg,
|
||||||
{
|
{
|
||||||
taskFunction: () => {
|
taskFunction: () => {
|
||||||
let done = plugins.Q.defer();
|
let done = plugins.Q.defer();
|
||||||
let promiseArray; // stores promises of all tasks, since they run in parallel
|
let promiseArray:PromiseLike<any>[] = []; // stores promises of all tasks, since they run in parallel
|
||||||
this.taskArray.forEach(function(taskArg:Task){
|
this.taskArray.forEach(function (taskArg) {
|
||||||
promiseArray.push(taskArg.trigger());
|
promiseArray.push(taskArg.trigger());
|
||||||
})
|
})
|
||||||
plugins.Q.all(promiseArray)
|
plugins.Q.all(promiseArray)
|
||||||
@ -21,8 +21,9 @@ export class Taskparallel extends Task {
|
|||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
);
|
||||||
super(options);
|
super(options);
|
||||||
|
this.taskArray = optionsArg.taskArray;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user