Compare commits

..

96 Commits

Author SHA1 Message Date
eee146ae8b 2.1.4 2020-07-12 10:57:15 +00:00
ea8ef61c40 fix(core): update 2020-07-12 10:57:15 +00:00
70bb5b3f5d 2.1.3 2020-07-12 02:40:45 +00:00
5fa7312171 fix(core): update 2020-07-12 02:40:45 +00:00
cb85deeb3d 2.1.2 2020-07-12 00:48:51 +00:00
fdfb780c33 fix(core): update 2020-07-12 00:48:51 +00:00
f21b53b81d 2.1.1 2019-11-28 14:42:29 +00:00
0bf3b2ea8b fix(core): update 2019-11-28 14:42:28 +00:00
0e81b8bd94 2.1.0 2019-11-28 11:33:26 +00:00
138aefc499 feat(taskrunner): now has working taskrunner 2019-11-28 11:33:26 +00:00
af5fa857cc 2.0.16 2019-11-27 23:34:45 +00:00
f275f7e2f6 fix(core): update 2019-11-27 23:34:45 +00:00
ea1f434cdd 2.0.15 2019-09-23 18:06:43 +02:00
2cc212f210 fix(core): update 2019-09-23 18:06:43 +02:00
2d2788d1ca 2.0.14 2019-09-23 16:31:07 +02:00
de1652bac9 fix(core): update 2019-09-23 16:31:06 +02:00
5310bef1be 2.0.13 2019-09-22 15:18:28 +02:00
1a5c67efc1 2.0.12 2019-09-22 15:16:27 +02:00
df21ebd581 fix(core): update 2019-09-22 15:16:27 +02:00
3f749dfdd2 2.0.11 2019-09-18 19:15:56 +02:00
2a39543a75 fix(core): update 2019-09-18 19:15:56 +02:00
68f7d26d3b 2.0.10 2019-09-08 22:45:37 +02:00
6373a74fb3 fix(core): update 2019-09-08 22:45:36 +02:00
be3d2d41d6 2.0.9 2019-09-06 16:32:36 +02:00
2affa189a7 fix(core): update 2019-09-06 16:32:36 +02:00
8c4c2a552c 2.0.8 2019-09-05 11:35:26 +02:00
eff9c6e6c9 fix(core): update 2019-09-05 11:35:26 +02:00
4c7a373d98 2.0.7 2019-01-15 00:20:05 +01:00
6b93a2e7ac fix(core): update 2019-01-15 00:20:05 +01:00
9c6487c779 2.0.6 2019-01-15 00:17:45 +01:00
e3f37f5027 fix(core): update 2019-01-15 00:17:44 +01:00
1152bb1138 2.0.5 2018-08-12 20:55:07 +02:00
9df7787450 2.0.4 2018-08-11 00:01:19 +02:00
3e81fdacad fix(CI): now building properly 2018-08-11 00:01:19 +02:00
f74da6ff0b 2.0.3 2018-08-05 23:10:01 +02:00
e9d976ad1e fix(ci): update testing framework to the new tstest 2018-08-05 23:10:00 +02:00
f6d314695a 2.0.2 2018-08-04 18:03:23 +02:00
d35b34f4aa fix(package.json): update private param 2018-08-04 18:03:22 +02:00
9fec5ce62e 2.0.1 2018-08-04 18:02:41 +02:00
7577479368 fix(docs): update docs 2018-08-04 18:02:41 +02:00
dbcd5bbfc8 2.0.0 2018-08-04 18:00:22 +02:00
d91b6c8360 BREAKING CHANGE(scope): switch to pushrocks scope 2018-08-04 18:00:21 +02:00
b9af186190 update 2018-08-04 17:59:01 +02:00
bdb7064394 update 2018-08-04 17:58:46 +02:00
f60deddadd fix(tests): now using tstest 2018-08-04 17:53:22 +02:00
df18aba4b5 1.0.22 2017-07-12 16:45:21 +02:00
a3699f2869 introduce TaskOnce 2017-07-12 16:45:18 +02:00
017c0789ca 1.0.21 2017-07-10 14:29:02 +02:00
6e6d056617 update docs 2017-07-10 14:28:58 +02:00
3f7f38ee17 1.0.20 2017-07-10 12:49:04 +02:00
5bfc72a602 add docs 2017-07-10 12:48:57 +02:00
ca8882962e 1.0.19 2017-07-10 12:45:36 +02:00
df6bf2c681 updated dependencies 2017-07-10 12:45:33 +02:00
310a683e14 1.0.18 2017-07-10 12:42:11 +02:00
3f275ebc08 implemented execDelay 2017-07-10 12:42:06 +02:00
01d469960e 1.0.17 2017-06-18 13:25:12 +02:00
2ed701040a now has working TaskManager 2017-06-18 13:25:09 +02:00
ca3bb38205 update test texts 2017-06-17 17:29:26 +02:00
891d727fd4 1.0.16 2017-06-17 16:56:37 +02:00
e1424ea0fb implement TaskManager 2017-06-17 16:56:33 +02:00
cf1b31d635 1.0.15 2017-06-09 23:34:40 +02:00
d5570311ee update ci 2017-06-09 23:34:37 +02:00
44b3ba1313 1.0.14 2017-06-09 23:33:45 +02:00
4721d8c9e6 clean up code 2017-06-09 23:33:41 +02:00
c7336eedfb 1.0.13 2017-06-09 23:26:25 +02:00
5477911b5e update to latest standards 2017-06-09 23:26:23 +02:00
2f8d3f7625 1.0.12 2017-02-15 22:52:34 +01:00
b00d31b41a update dependencies 2017-02-15 22:52:29 +01:00
4031692f6f 1.0.11 2017-01-20 21:36:21 +01:00
174beae65f fix test 2017-01-20 21:36:18 +01:00
c1144d3405 add taskmanager class 2017-01-20 20:48:07 +01:00
065d92e573 1.0.10 2017-01-20 18:54:28 +01:00
46878819df add better readme 2017-01-20 18:54:23 +01:00
aa8df29bbb 1.0.9 2017-01-20 18:50:43 +01:00
f5cb0843fc smartq now working 2017-01-20 18:50:37 +01:00
1d52d098fb Merge branch 'master' into 'master'
update from q to smartq

See merge request !1
2017-01-20 08:33:32 +00:00
eb7eb14415 update from q to smartq 2017-01-19 17:26:35 +01:00
670bf5b124 1.0.8 2016-09-02 18:11:49 +02:00
fab863c66c update dependencies 2016-09-02 18:11:33 +02:00
402e2b982f 1.0.7 2016-08-03 14:51:47 +02:00
1d0a85e6ca now returning correct Promise types 2016-08-03 14:51:43 +02:00
7ded7b036e 1.0.6 2016-08-03 12:14:29 +02:00
03020eacbc update type versions 2016-08-03 12:14:21 +02:00
dc95885646 1.0.5 2016-08-03 11:28:21 +02:00
11cdaad226 add error catching 2016-08-03 11:28:13 +02:00
a1ad463140 1.0.4 2016-08-02 11:10:08 +02:00
76c57451b3 values now flow correctly between tasks 2016-08-02 11:09:42 +02:00
5dca9a9460 1.0.3 2016-08-01 16:10:06 +02:00
d30fb551f9 now running correctly in buffered mode 2016-08-01 16:10:00 +02:00
7a60f30f0b 1.0.2 2016-08-01 13:35:38 +02:00
9e175245ed update README 2016-08-01 13:35:33 +02:00
4bc5617240 1.0.1 2016-08-01 13:19:50 +02:00
39c41a817e now exporting interfaces 2016-08-01 13:19:42 +02:00
8823e2b01d 1.0.0 2016-08-01 13:17:36 +02:00
24e96926e3 update taskbuffer and add gitlab ci 2016-08-01 13:17:15 +02:00
8a414b9a7d update structure 2016-08-01 00:53:27 +02:00
55 changed files with 11325 additions and 886 deletions

25
.gitignore vendored
View File

@ -1,7 +1,20 @@
.idea/
.nogit/
# artifacts
coverage/
docs/
ts/*.js
ts/*.js.map
ts/typings/
node_modules
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

127
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,127 @@
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci git mirror
tags:
- lossless
- docker
- notpriv
audit:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high
tags:
- lossless
- docker
- notpriv
# ====================
# test stage
# ====================
testStable:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- priv
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- notpriv
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
script:
- npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
stage: metadata
script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- lossless
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

View File

@ -1,5 +1,5 @@
.idea/
docs/
coverage/
ts/
node_modules/
pages/

View File

@ -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

29
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"request": "launch",
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
}
]
}

26
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm"]
}
}
}
}
}
}
]
}

View File

@ -1,56 +0,0 @@
# taskbuffer
Flexible task organization for gulp. TypeScript ready!
## Status
[![Coverage Status](https://coveralls.io/repos/github/pushrocks/taskbuffer/badge.svg?branch=master)](https://coveralls.io/github/pushrocks/taskbuffer?branch=master)
## Install
```sh
npm install taskbuffer --save
```
## Concepts
### class `Task`
* A Task in its most simple form is a function that is executed when the task runs.
* A Task can have a **preTask** and an **afterTask**
(those are run before or after the main function whenever the task is called)
* A Task can be buffered.
That means it can be called multiple times in a very short time.
However execution happens in line:
meaning execution of the task's main function is on halt until the previous task call has finished.
You can set bufferMax number, which is the max number of buffered task calls.
Any additional calls will then be truncated
* Task.trigger() and Task.triggerBuffered() always return a Promise
which is fullfilled once the related task call has completed.
* Task.triggered() is an Observable stream that emits events every time a task call is called and every time a call is completed.
* Task is compatible to gulp streams.
### class `TaskChain`
* TaskChain extends Task.
* Multiple Tasks can be combined in a bigger task using a TaskChain.
* While the tasks are async in themselve, TaskChain **runs Tasks serialized** (one after the other)
* that means that tasks can rely on each other and
### class `TaskParallel`
* TaskParallel extends Task.
* like TaskChain, however **tasks run in parallel**
* Tasks cannot rely on each other.
### Usage
We highly recommend TypeScript as this module supports **TypeScript intellisense**.
```
import * as taskbuffer from "taskbuffer";
myTask = new taskbuffer.Task({
preTask: someOtherTask // optional, don't worry loops are prevented
afterTask: someOtherTask // optional, don't worry loops are prevented
name:"myTask1",
taskFunction:() => {
// do some stuff and return promise
// pass on any data through promise resolution
// Use TypeScript for better understanding and code completion
}
})
```

5
dist/index.d.ts vendored
View File

@ -1,5 +0,0 @@
export { Task } from "./taskbuffer.classes.task";
export { Taskchain } from "./taskbuffer.classes.taskchain";
export { Taskparallel } from "./taskbuffer.classes.taskparallel";
export { Taskspace } from "./taskbuffer.classes.taskspace";
import "./taskbuffer.classes.helpers";

14
dist/index.js vendored
View File

@ -1,14 +0,0 @@
"use strict";
/// <reference path="./typings/main.d.ts" />
var taskbuffer_classes_task_1 = require("./taskbuffer.classes.task");
exports.Task = taskbuffer_classes_task_1.Task;
var taskbuffer_classes_taskchain_1 = require("./taskbuffer.classes.taskchain");
exports.Taskchain = taskbuffer_classes_taskchain_1.Taskchain;
var taskbuffer_classes_taskparallel_1 = require("./taskbuffer.classes.taskparallel");
exports.Taskparallel = taskbuffer_classes_taskparallel_1.Taskparallel;
var taskbuffer_classes_taskspace_1 = require("./taskbuffer.classes.taskspace");
exports.Taskspace = taskbuffer_classes_taskspace_1.Taskspace;
// import for naming only
require("./taskbuffer.classes.helpers");
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSw0Q0FBNEM7QUFDNUMsd0NBQW1CLDJCQUEyQixDQUFDO0FBQXZDLDhDQUF1QztBQUMvQyw2Q0FBd0IsZ0NBQWdDLENBQUM7QUFBakQsNkRBQWlEO0FBQ3pELGdEQUEyQixtQ0FBbUMsQ0FBQztBQUF2RCxzRUFBdUQ7QUFDL0QsNkNBQXdCLGdDQUFnQyxDQUFDO0FBQWpELDZEQUFpRDtBQUV6RCx5QkFBeUI7QUFDekIsUUFBTyw4QkFBOEIsQ0FBQyxDQUFEIiwiZmlsZSI6ImluZGV4LmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cIi4vdHlwaW5ncy9tYWluLmQudHNcIiAvPlxyXG5leHBvcnQge1Rhc2t9IGZyb20gXCIuL3Rhc2tidWZmZXIuY2xhc3Nlcy50YXNrXCI7XHJcbmV4cG9ydCB7VGFza2NoYWlufSBmcm9tIFwiLi90YXNrYnVmZmVyLmNsYXNzZXMudGFza2NoYWluXCI7XHJcbmV4cG9ydCB7VGFza3BhcmFsbGVsfSBmcm9tIFwiLi90YXNrYnVmZmVyLmNsYXNzZXMudGFza3BhcmFsbGVsXCI7XHJcbmV4cG9ydCB7VGFza3NwYWNlfSBmcm9tIFwiLi90YXNrYnVmZmVyLmNsYXNzZXMudGFza3NwYWNlXCI7XHJcblxyXG4vLyBpbXBvcnQgZm9yIG5hbWluZyBvbmx5XHJcbmltcG9ydCBcIi4vdGFza2J1ZmZlci5jbGFzc2VzLmhlbHBlcnNcIiJdfQ==

View File

@ -1,9 +0,0 @@
import { Task } from "./taskbuffer.classes.task";
export declare let emptyTaskFunction: () => any;
export declare let isTask: (taskArg: any) => boolean;
export declare let isTaskTouched: (taskArg: Task, touchedTasksArray: Task[]) => boolean;
export declare let runTask: (taskArg: Task, optionsArg?: {
touchedTasksArray: Task[];
}) => any;
export declare let runBufferedTask: (taskArg: Task) => void;
export declare let updateTaskStatus: (taskArg: any, statusArg: string) => void;

File diff suppressed because one or more lines are too long

View File

@ -1,25 +0,0 @@
export declare class Task {
name: string;
task: any;
running: boolean;
idle: boolean;
buffered: boolean;
bufferCounter: number;
bufferMax: number;
private _counterTriggerAbsolute;
private _state;
preTask: Task;
afterTask: Task;
constructor(optionsArg: {
taskFunction: any;
preTask?: Task;
afterTask?: Task;
buffered?: boolean;
bufferMax?: number;
name?: string;
});
trigger(): any;
triggerUnBuffered(): any;
triggerBuffered(): any;
state: string;
}

File diff suppressed because one or more lines are too long

View File

@ -1,14 +0,0 @@
import { Task } from "./taskbuffer.classes.task";
export declare class Taskchain extends Task {
taskArray: Task[];
private _oraObject;
constructor(optionsArg: {
name?: string;
log?: boolean;
taskArray: Task[];
});
addTask(taskArg: Task): void;
removeTask(taskArg: Task): void;
shiftTask(): void;
trigger(): any;
}

File diff suppressed because one or more lines are too long

View File

@ -1,7 +0,0 @@
import { Task } from "./taskbuffer.classes.task";
export declare class Taskparallel extends Task {
taskArray: Task[];
constructor(optionsArg: {
taskArray: Task[];
});
}

View File

@ -1,32 +0,0 @@
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
/// <reference path="./typings/main.d.ts" />
var plugins = require("./taskbuffer.plugins");
var taskbuffer_classes_task_1 = require("./taskbuffer.classes.task");
var Taskparallel = (function (_super) {
__extends(Taskparallel, _super);
function Taskparallel(optionsArg) {
var _this = this;
var options = plugins.lodash.assign(optionsArg, {
taskFunction: function () {
var done = plugins.Q.defer();
var promiseArray; // stores promises of all tasks, since they run in parallel
_this.taskArray.forEach(function (taskArg) {
promiseArray.push(taskArg.trigger());
});
plugins.Q.all(promiseArray)
.then(done.resolve);
return done.promise;
}
});
_super.call(this, options);
}
return Taskparallel;
}(taskbuffer_classes_task_1.Task));
exports.Taskparallel = Taskparallel;
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRhc2tidWZmZXIuY2xhc3Nlcy50YXNrcGFyYWxsZWwudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBQUEsNENBQTRDO0FBQzVDLElBQVksT0FBTyxXQUFNLHNCQUN6QixDQUFDLENBRDhDO0FBRS9DLHdDQUFtQiwyQkFFbkIsQ0FBQyxDQUY2QztBQUU5QztJQUFrQyxnQ0FBSTtJQUVsQyxzQkFBWSxVQUVYO1FBSkwsaUJBc0JDO1FBakJPLElBQUksT0FBTyxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsTUFBTSxDQUMvQixVQUFVLEVBQ1Y7WUFDSSxZQUFZLEVBQUM7Z0JBQ1QsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztnQkFDN0IsSUFBSSxZQUFZLENBQUMsQ0FBQywyREFBMkQ7Z0JBQzdFLEtBQUksQ0FBQyxTQUFTLENBQUMsT0FBTyxDQUFDLFVBQVMsT0FBWTtvQkFDeEMsWUFBWSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsT0FBTyxFQUFFLENBQUMsQ0FBQztnQkFDekMsQ0FBQyxDQUFDLENBQUE7Z0JBQ0YsT0FBTyxDQUFDLENBQUMsQ0FBQyxHQUFHLENBQUMsWUFBWSxDQUFDO3FCQUN0QixJQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxDQUFDO2dCQUN4QixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQztZQUN4QixDQUFDO1NBQ0osQ0FDSixDQUFBO1FBQ0Qsa0JBQU0sT0FBTyxDQUFDLENBQUM7SUFDbkIsQ0FBQztJQUNMLG1CQUFDO0FBQUQsQ0F0QkEsQUFzQkMsQ0F0QmlDLDhCQUFJLEdBc0JyQztBQXRCWSxvQkFBWSxlQXNCeEIsQ0FBQSIsImZpbGUiOiJ0YXNrYnVmZmVyLmNsYXNzZXMudGFza3BhcmFsbGVsLmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cIi4vdHlwaW5ncy9tYWluLmQudHNcIiAvPlxyXG5pbXBvcnQgKiBhcyBwbHVnaW5zIGZyb20gXCIuL3Rhc2tidWZmZXIucGx1Z2luc1wiXHJcbmltcG9ydCAqIGFzIGhlbHBlcnMgZnJvbSBcIi4vdGFza2J1ZmZlci5jbGFzc2VzLmhlbHBlcnNcIlxyXG5pbXBvcnQge1Rhc2t9IGZyb20gXCIuL3Rhc2tidWZmZXIuY2xhc3Nlcy50YXNrXCJcclxuXHJcbmV4cG9ydCBjbGFzcyBUYXNrcGFyYWxsZWwgZXh0ZW5kcyBUYXNrIHtcclxuICAgIHRhc2tBcnJheTpUYXNrW107XHJcbiAgICBjb25zdHJ1Y3RvcihvcHRpb25zQXJnOntcclxuICAgICAgICB0YXNrQXJyYXk6VGFza1tdXHJcbiAgICB9KXtcclxuICAgICAgICBsZXQgb3B0aW9ucyA9IHBsdWdpbnMubG9kYXNoLmFzc2lnbihcclxuICAgICAgICAgICAgb3B0aW9uc0FyZyxcclxuICAgICAgICAgICAge1xyXG4gICAgICAgICAgICAgICAgdGFza0Z1bmN0aW9uOigpID0+IHtcclxuICAgICAgICAgICAgICAgICAgICBsZXQgZG9uZSA9IHBsdWdpbnMuUS5kZWZlcigpO1xyXG4gICAgICAgICAgICAgICAgICAgIGxldCBwcm9taXNlQXJyYXk7IC8vIHN0b3JlcyBwcm9taXNlcyBvZiBhbGwgdGFza3MsIHNpbmNlIHRoZXkgcnVuIGluIHBhcmFsbGVsXHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy50YXNrQXJyYXkuZm9yRWFjaChmdW5jdGlvbih0YXNrQXJnOlRhc2spe1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBwcm9taXNlQXJyYXkucHVzaCh0YXNrQXJnLnRyaWdnZXIoKSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSlcclxuICAgICAgICAgICAgICAgICAgICBwbHVnaW5zLlEuYWxsKHByb21pc2VBcnJheSlcclxuICAgICAgICAgICAgICAgICAgICAgICAgLnRoZW4oZG9uZS5yZXNvbHZlKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gZG9uZS5wcm9taXNlO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgKVxyXG4gICAgICAgIHN1cGVyKG9wdGlvbnMpO1xyXG4gICAgfVxyXG59XHJcblxyXG4iXX0=

View File

@ -1,2 +0,0 @@
export declare class Taskspace {
}

View File

@ -1,9 +0,0 @@
"use strict";
var Taskspace = (function () {
function Taskspace() {
}
return Taskspace;
}());
exports.Taskspace = Taskspace;
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRhc2tidWZmZXIuY2xhc3Nlcy50YXNrc3BhY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUlBO0lBQUE7SUFFQSxDQUFDO0lBQUQsZ0JBQUM7QUFBRCxDQUZBLEFBRUMsSUFBQTtBQUZZLGlCQUFTLFlBRXJCLENBQUEiLCJmaWxlIjoidGFza2J1ZmZlci5jbGFzc2VzLnRhc2tzcGFjZS5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCIuL3R5cGluZ3MvbWFpbi5kLnRzXCIgLz5cclxuaW1wb3J0ICogYXMgcGx1Z2lucyBmcm9tIFwiLi90YXNrYnVmZmVyLnBsdWdpbnNcIlxyXG5pbXBvcnQgKiBhcyBoZWxwZXJzIGZyb20gXCIuL3Rhc2tidWZmZXIuY2xhc3Nlcy5oZWxwZXJzXCJcclxuXHJcbmV4cG9ydCBjbGFzcyBUYXNrc3BhY2Uge1xyXG4gICAgXHJcbn0iXX0=

View File

@ -1,3 +0,0 @@
export import beautylog = require("beautylog");
export declare let Q: any;
export declare let lodash: any;

View File

@ -1,7 +0,0 @@
"use strict";
/// <reference path="./typings/main.d.ts" />
exports.beautylog = require("beautylog");
exports.Q = require("q");
exports.lodash = require("lodash");
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRhc2tidWZmZXIucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsNENBQTRDO0FBQzlCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDcEMsU0FBQyxHQUFHLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNqQixjQUFNLEdBQUUsT0FBTyxDQUFDLFFBQVEsQ0FBQyxDQUFDIiwiZmlsZSI6InRhc2tidWZmZXIucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCIuL3R5cGluZ3MvbWFpbi5kLnRzXCIgLz5cclxuZXhwb3J0IGltcG9ydCBiZWF1dHlsb2cgPSByZXF1aXJlKFwiYmVhdXR5bG9nXCIpO1xyXG5leHBvcnQgbGV0IFEgPSByZXF1aXJlKFwicVwiKTtcclxuZXhwb3J0IGxldCBsb2Rhc2g9IHJlcXVpcmUoXCJsb2Rhc2hcIik7XHJcbiJdfQ==

18
npmextra.json Normal file
View File

@ -0,0 +1,18 @@
{
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public",
"npmRegistryUrl": "registry.npmjs.org"
},
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "taskbuffer",
"shortDescription": "flexible task management. TypeScript ready!",
"npmPackagename": "@pushrocks/taskbuffer",
"license": "MIT"
}
}
}

View File

@ -1,4 +0,0 @@
{
"mode":"default",
"coveralls":true
}

9916
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,37 +1,62 @@
{
"name": "taskbuffer",
"version": "0.1.3",
"description": "Flexible task organization for gulp. TypeScript ready!",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"name": "@pushrocks/taskbuffer",
"version": "2.1.4",
"private": false,
"description": "flexible task management. TypeScript ready!",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"scripts": {
"test": "(npmts)"
"test": "(tstest test/ --web)",
"build": "(tsbuild --web && tsbundle npm)"
},
"repository": {
"type": "git",
"url": "git+https://github.com/pushrocks/taskbuffer.git"
"url": "git+https://gitlab.com/pushrocks/taskbuffer.git"
},
"keywords": [
"gulp",
"tasks",
"watch",
"buffer"
"task",
"buffer",
"TypeScript",
"push.rocks"
],
"author": "Lossless GmbH",
"license": "MIT",
"bugs": {
"url": "https://github.com/pushrocks/taskbuffer/issues"
"url": "https://gitlab.com/pushrocks/taskbuffer/issues"
},
"homepage": "https://github.com/pushrocks/taskbuffer#readme",
"homepage": "https://gitlab.com/pushrocks/taskbuffer#readme",
"dependencies": {
"beautylog": "^5.0.0",
"lodash": "^4.12.0",
"projectinfo": "1.0.1",
"q": "^1.4.1",
"rx": "^4.1.0"
"@pushrocks/lik": "^4.0.14",
"@pushrocks/smartdelay": "^2.0.10",
"@pushrocks/smartlog": "^2.0.35",
"@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartrx": "^2.0.18",
"@pushrocks/smarttime": "^3.0.24",
"@types/cron": "^1.7.2"
},
"devDependencies": {
"should": "^8.3.1",
"npmts": "^5.1.5"
}
"@gitzone/tsbuild": "^2.1.24",
"@gitzone/tsbundle": "^1.0.72",
"@gitzone/tstest": "^1.0.43",
"@pushrocks/tapbundle": "^3.2.9",
"@types/node": "^14.0.22",
"tslint": "^6.1.2",
"tslint-config-prettier": "^1.18.0"
},
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
]
}

63
readme.md Normal file
View File

@ -0,0 +1,63 @@
# @pushrocks/taskbuffer
flexible task management. TypeScript ready!
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/taskbuffer)
* [gitlab.com (source)](https://gitlab.com/pushrocks/taskbuffer)
* [github.com (source mirror)](https://github.com/pushrocks/taskbuffer)
* [docs (typedoc)](https://pushrocks.gitlab.io/taskbuffer/)
## Status for master
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/taskbuffer/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/taskbuffer/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/taskbuffer)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/taskbuffer)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/taskbuffer)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/taskbuffer)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/taskbuffer)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage
We highly recommend TypeScript as this module supports **TypeScript intellisense**.
```javascript
import * as taskbuffer from "taskbuffer";
myTask = new taskbuffer.Task({
preTask: someOtherTask // optional, don't worry loops are prevented
afterTask: someOtherTask // optional, don't worry loops are prevented
name:"myTask1",
buffered: true, // optional
bufferMax: 3, // optional, call qeues greater than this are truncated
execDelay: 1000, // optional, time in ms to wait before executing task call
taskFunction:() => {
// do some stuff and return promise
// pass on any data through promise resolution
// Use TypeScript for better understanding and code completion
}
})
```
For further information read the linked docs at the top of this README.
> MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
For further information read the linked docs at the top of this readme.
> MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

115
test/test.1.task.ts Normal file
View File

@ -0,0 +1,115 @@
import { expect, tap } from '@pushrocks/tapbundle';
import taskbuffer = require('../ts/index');
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartdelay from '@pushrocks/smartdelay';
// setup some testData to work with
let testTask: taskbuffer.Task;
let testPreTask = new taskbuffer.Task({
taskFunction: async () => {
console.log('preTask executed');
},
preTask: testTask,
});
// some more tasks to test with
let task1Counter = 0; // how often task 1 is being executed
let task1 = new taskbuffer.Task({
name: 'Task 1',
taskFunction: () => {
let done = smartpromise.defer();
console.log('Task1 started');
setTimeout(() => {
task1Counter++;
console.log('Task1 executed');
done.resolve();
}, 5000);
return done.promise;
},
});
let task2 = new taskbuffer.Task({
name: 'Task 1',
taskFunction: async () => {
const done = smartpromise.defer();
console.log('Task2 started');
setTimeout(() => {
console.log('Task2 executed');
done.resolve();
}, 5000);
await done.promise;
},
});
let task3 = new taskbuffer.Task({
name: 'Task 3',
taskFunction: () => {
let done = smartpromise.defer();
console.log('Task3 started');
setTimeout(() => {
console.log('Task3 executed');
done.resolve();
}, 5000);
return done.promise;
},
});
tap.test('new Task() should return a new task', async () => {
testTask = new taskbuffer.Task({
taskFunction: async () => {
console.log('executed twice');
},
preTask: testPreTask,
});
});
tap.test('expect testTask to be an instance of Task', async () => {
expect(testTask).to.be.instanceof(taskbuffer.Task);
});
tap.test('expect testTask.idle is true', async () => {
if (!testTask.idle) {
throw new Error('testTask.idle is not true');
}
});
tap.test('testTask.running should be of type boolean and initially false', async () => {
expect(testTask.running).to.be.a('boolean');
// tslint:disable-next-line:no-unused-expression
expect(testTask.running).to.be.false;
});
tap.test('testTask.trigger() should return Promise', async () => {
expect(testTask.trigger()).to.be.instanceof(Promise);
});
tap.test('testTask.trigger() returned Promise should be fullfilled', async () => {
await testTask.trigger();
});
tap.test('expect to run a task without pre and afterTask errorless', async () => {
let localTestTask = new taskbuffer.Task({
taskFunction: async () => {
console.log('only once');
},
});
await localTestTask.trigger();
});
tap.test('expect task to run in buffered mode', async () => {
let localTestTask = new taskbuffer.Task({
taskFunction: async () => {
await smartdelay.delayFor(3000);
},
buffered: true,
bufferMax: 2,
});
localTestTask.trigger();
localTestTask.trigger();
localTestTask.trigger();
await localTestTask.trigger();
});
tap.start();

48
test/test.2.taskchain.ts Normal file
View File

@ -0,0 +1,48 @@
import { expect, tap } from '@pushrocks/tapbundle';
import taskbuffer = require('../ts/index');
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartdelay from '@pushrocks/smartdelay';
let task1Executed = false;
const task1 = new taskbuffer.Task({
taskFunction: async () => {
await smartdelay.delayFor(2000);
task1Executed = true;
},
});
let task2Executed = false;
const task2 = new taskbuffer.Task({
taskFunction: async () => {
await smartdelay.delayFor(2000);
task2Executed = true;
},
});
let task3Executed = false;
const task3 = new taskbuffer.Task({
taskFunction: async () => {
await smartdelay.delayFor(2000);
task3Executed = true;
},
});
tap.test('expect run tasks in sequence', async () => {
const testTaskchain = new taskbuffer.Taskchain({
name: 'Taskchain1',
taskArray: [task1, task2, task3],
});
const testPromise = testTaskchain.trigger();
await smartdelay.delayFor(2100);
// tslint:disable-next-line:no-unused-expression
expect(task1Executed).to.be.true;
// tslint:disable-next-line:no-unused-expression
expect(task2Executed).to.be.false;
await smartdelay.delayFor(2100);
// tslint:disable-next-line:no-unused-expression
expect(task2Executed).to.be.true;
await testPromise;
});
tap.start();

View File

@ -0,0 +1,36 @@
import { expect, tap } from '@pushrocks/tapbundle';
import taskbuffer = require('../ts/index');
import * as smartdelay from '@pushrocks/smartdelay';
let task1Executed = false;
const task1 = new taskbuffer.Task({
taskFunction: async () => {
await smartdelay.delayFor(2000);
task1Executed = true;
},
});
let task2Executed = false;
const task2 = new taskbuffer.Task({
taskFunction: async () => {
await smartdelay.delayFor(2000);
task2Executed = true;
},
});
let task3Executed = false;
const task3 = new taskbuffer.Task({
taskFunction: async () => {
await smartdelay.delayFor(2000);
task3Executed = true;
},
});
tap.test('expect run in Parallel', async () => {
const testTaskparallel = new taskbuffer.Taskparallel({
taskArray: [task1, task2, task3],
});
await testTaskparallel.trigger();
});
tap.start();

View File

@ -0,0 +1,42 @@
import { expect, tap } from '@pushrocks/tapbundle';
import taskbuffer = require('../ts/index');
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartdelay from '@pushrocks/smartdelay';
let myTaskManager: taskbuffer.TaskManager;
let taskRunCounter = 0;
const taskDone = smartpromise.defer();
tap.test('should create an instance of TaskManager', async () => {
myTaskManager = new taskbuffer.TaskManager();
expect(myTaskManager).to.be.instanceof(taskbuffer.TaskManager);
});
tap.test('should run the task as expected', async () => {
let referenceBoolean = false;
myTaskManager.addTask(
new taskbuffer.Task({
name: 'myTask',
taskFunction: async () => {
console.log('Task executed!');
referenceBoolean = true;
taskRunCounter++;
if (taskRunCounter === 10) {
taskDone.resolve();
}
},
})
);
await myTaskManager.triggerTaskByName('myTask');
// tslint:disable-next-line:no-unused-expression
expect(referenceBoolean).to.be.true;
});
tap.test('should schedule task', async () => {
myTaskManager.scheduleTaskByName('myTask', '* * * * * *');
await taskDone.promise;
myTaskManager.descheduleTaskByName('myTask');
});
tap.start();

View File

@ -0,0 +1,42 @@
import { expect, tap } from '@pushrocks/tapbundle';
import taskbuffer = require('../ts/index');
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartdelay from '@pushrocks/smartdelay';
let myTaskManager: taskbuffer.TaskManager;
let taskRunCounter = 0;
const taskDone = smartpromise.defer();
tap.test('should create an instance of TaskManager', async () => {
myTaskManager = new taskbuffer.TaskManager();
expect(myTaskManager).to.be.instanceof(taskbuffer.TaskManager);
});
tap.test('should run the task as expected', async () => {
let referenceBoolean = false;
myTaskManager.addTask(
new taskbuffer.Task({
name: 'myTask',
taskFunction: async () => {
console.log('Task executed!');
referenceBoolean = true;
taskRunCounter++;
if (taskRunCounter === 10) {
taskDone.resolve();
}
},
})
);
await myTaskManager.triggerTaskByName('myTask');
// tslint:disable-next-line:no-unused-expression
expect(referenceBoolean).to.be.true;
});
tap.test('should schedule task', async () => {
myTaskManager.scheduleTaskByName('myTask', '* * * * * *');
await taskDone.promise;
myTaskManager.descheduleTaskByName('myTask');
});
tap.start();

View File

@ -0,0 +1,64 @@
import { expect, tap } from '@pushrocks/tapbundle';
import taskbuffer = require('../ts/index');
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartdelay from '@pushrocks/smartdelay';
const flowTask1 = new taskbuffer.Task({
taskFunction: (x: number) => {
const done = smartpromise.defer();
console.log('flowTask1');
console.log(x);
done.resolve(x);
return done.promise;
},
});
const flowTaskBuffered = new taskbuffer.Task({
taskFunction: (x: number) => {
const done = smartpromise.defer();
console.log('flowTask1');
console.log(x);
done.resolve(x);
return done.promise;
},
buffered: true,
bufferMax: 1,
});
const flowTask2 = new taskbuffer.Task({
taskFunction: (x: number) => {
const done = smartpromise.defer();
console.log('flowTask2');
console.log(x);
done.resolve(x);
return done.promise;
},
preTask: flowTask1,
});
const flowTask3 = new taskbuffer.Taskchain({
taskArray: [flowTask1, flowTask2],
});
tap.test('should let a value flow through a task', async () => {
const result = await flowTask1.trigger(12);
expect(result).to.equal(12);
});
tap.test('expect values to flow between tasks', async () => {
const result = await flowTask2.trigger(12);
expect(result).to.equal(12);
});
tap.test('expect values to flow between tasks when buffered', async () => {
const result = await flowTaskBuffered.trigger(12);
expect(result).to.equal(12);
});
tap.test('expect values to flow between tasks in Taskchain', async () => {
const result = await flowTask3.trigger(12);
expect(result).to.equal(12);
});
tap.start();

28
test/test.6.taskonce.ts Normal file
View File

@ -0,0 +1,28 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as taskbuffer from '../ts/index';
let myNumber = 0;
let myTaskOnce: taskbuffer.TaskOnce;
tap.test('should create a valid instance of TaskOnce', async () => {
myTaskOnce = new taskbuffer.TaskOnce({
taskFunction: async () => {
myNumber++;
},
});
expect(myTaskOnce).to.be.instanceof(taskbuffer.TaskOnce);
});
tap.test('myNumber should still be 0', async () => {
expect(myNumber).to.equal(0);
});
tap.test('myTaskOnce should trigger once', async () => {
await myTaskOnce.trigger();
await myTaskOnce.trigger();
await myTaskOnce.trigger();
expect(myNumber).to.equal(1);
});
tap.start();

51
test/test.7.taskloop.ts Normal file
View File

@ -0,0 +1,51 @@
import { tap, expect } from '@pushrocks/tapbundle';
import * as taskbuffer from '../ts';
let preTask: taskbuffer.Task;
let afterTask: taskbuffer.Task;
let mainTask: taskbuffer.Task;
tap.test('should create tasks', async () => {
preTask = new taskbuffer.Task({
name: 'myPreTask',
taskFunction: async () => {
console.log('pretask executed :)');
return 'hi';
},
});
afterTask = new taskbuffer.Task({
name: 'myAfterTask',
taskFunction: async (x) => {
if (x === 'hi') {
console.log('afterTask: values get passed along alright');
}
console.log('afterTask executed :)');
return x;
},
preTask,
afterTask,
});
mainTask = new taskbuffer.Task({
name: 'mainTask',
taskFunction: async (x) => {
if (x === 'hi') {
console.log('mainTask: values get passed along alright');
}
console.log('afterTask executed :)');
return x;
},
preTask: () => {
return preTask;
},
afterTask,
});
});
tap.test('should execute the mainTask', async () => {
await mainTask.trigger();
});
tap.start();

0
test/test.d.ts vendored
View File

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
{"version":3,"file":"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,IAAI,UAAU,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;AAC1C,IAAI,OAAO,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;AACpD,IAAI,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAC/B,QAAQ,CAAC,YAAY,EAAC;IAClB,QAAQ,CAAC,SAAS,EAAC;QACf,IAAI,QAAQ,CAAC;QACb,EAAE,CAAC,0CAA0C,EAAC;YAC1C,QAAQ,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;QACjC,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,qCAAqC,EAAC;YACrC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,uBAAuB,EAAC;YACvB,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA,CAAC;gBAChB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;YACjD,CAAC;QACL,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,sDAAsD,EAAC;YACtD,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC3C,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;QACvC,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}

33
test/test.taskrunner.ts Normal file
View File

@ -0,0 +1,33 @@
import { tap, expect } from '@pushrocks/tapbundle';
import * as taskbuffer from '../ts/index';
let testTaskRunner: taskbuffer.TaskRunner;
tap.test('should create a valid taskrunner', async () => {
testTaskRunner = new taskbuffer.TaskRunner();
await testTaskRunner.start();
});
tap.test('should execute task when its scheduled', async (tools) => {
const done = tools.defer();
testTaskRunner.addTask(
new taskbuffer.Task({
taskFunction: async () => {
console.log('hi');
},
})
);
testTaskRunner.addTask(
new taskbuffer.Task({
taskFunction: async () => {
console.log('there');
done.resolve();
},
})
);
await done.promise;
});
tap.start();

View File

@ -1,83 +0,0 @@
/// <reference path="../ts/typings/main.d.ts" />
import taskbuffer = require("../dist/index");
let should = require("should");
let plugins = {
q: require("q")
}
// setup some testData to work with
let testTask:taskbuffer.Task;
let testTaskFunction = function(){
let done = plugins.q.defer();
console.log("main function executed!")
done.resolve();
return done.promise;
}
let testPreTask = new taskbuffer.Task({
taskFunction:function(){
console.log("preTask executed");
},
preTask:testTask
});
describe("taskbuffer",function(){
describe(".Task",function(){
it("new Task() should return a new task",function(){
testTask = new taskbuffer.Task({taskFunction:testTaskFunction,preTask:testPreTask});
});
it("testTask should be and instance of Task",function(){
testTask.should.be.instanceof(taskbuffer.Task);
});
it("testTask.idle is true",function(){
if (!testTask.idle){
throw new Error("testTask.idle is not true");
}
});
it("testTask.running is type boolean and initially false",function(){
testTask.running.should.be.type("boolean");
testTask.running.should.be.false();
});
it("testTask.trigger() should return Promise",function(){
testTask.trigger().should.be.Promise();
});
it("testTask.trigger() returned Promise should be fullfilled",function(done){
testTask.trigger()
.then(done);
});
it("should run a task without pre and afterTask",function(done){
let localTestTask = new taskbuffer.Task({taskFunction:testTaskFunction});
localTestTask.trigger().then(done);
});
});
describe("Taskchain",function(){
let testTaskchain;
let testTaskArray = [
new taskbuffer.Task({
name:"task1",
taskFunction:function(){
let done = plugins.q.defer();
setTimeout(done.resolve,2000);
return done.promise;
}
}),
new taskbuffer.Task({
name:"task2",
taskFunction: function(){
let done = plugins.q.defer();
setTimeout(done.resolve,2000);
return done.promise;
}
}),
];
it("should run tasks in sequence",function(done){
this.timeout(5000);
testTaskchain = new taskbuffer.Taskchain({
name:"Taskchain1",
taskArray:testTaskArray
});
testTaskchain.trigger().then(done);
});
});
});

View File

@ -1,8 +1,7 @@
/// <reference path="./typings/main.d.ts" />
export {Task} from "./taskbuffer.classes.task";
export {Taskchain} from "./taskbuffer.classes.taskchain";
export {Taskparallel} from "./taskbuffer.classes.taskparallel";
export {Taskspace} from "./taskbuffer.classes.taskspace";
// import for naming only
import "./taskbuffer.classes.helpers"
export { Task, ITaskFunction } from './taskbuffer.classes.task';
export { Taskchain } from './taskbuffer.classes.taskchain';
export { Taskparallel } from './taskbuffer.classes.taskparallel';
export { TaskManager } from './taskbuffer.classes.taskmanager';
export { TaskOnce } from './taskbuffer.classes.taskonce';
export { TaskRunner } from './taskbuffer.classes.taskrunner';
export { TaskDebounced } from './taskbuffer.classes.taskdebounced';

View File

@ -0,0 +1,42 @@
import { Task } from './taskbuffer.classes.task';
export class BufferRunner {
public task: Task;
// initialze by default
public bufferCounter: number = 0;
public running: boolean = false;
constructor(taskArg: Task) {
this.task = taskArg;
}
public trigger(x): Promise<any> {
if (!(this.bufferCounter >= this.task.bufferMax)) {
this.bufferCounter++;
}
const returnPromise: Promise<any> = this.task.cycleCounter.getPromiseForCycle(
this.bufferCounter + 1
);
if (!this.running) {
this._run(x);
}
return returnPromise;
}
private _run(x) {
const recursiveBufferRunner = (x) => {
if (this.bufferCounter >= 0) {
this.running = true;
this.task.running = true;
Task.runTask(this.task, { x: x }).then((x) => {
this.bufferCounter--;
this.task.cycleCounter.informOfCycle(x);
recursiveBufferRunner(x);
});
} else {
this.running = false;
this.task.running = false;
}
};
recursiveBufferRunner(x);
}
}

View File

@ -0,0 +1,36 @@
import * as plugins from './taskbuffer.plugins';
import { Task } from './taskbuffer.classes.task';
export interface ICycleObject {
cycleCounter: number;
deferred: plugins.smartpromise.Deferred<any>;
}
export class CycleCounter {
public task: Task;
public cycleObjectArray: ICycleObject[] = [];
constructor(taskArg: Task) {
this.task = taskArg;
}
public getPromiseForCycle(cycleCountArg: number) {
const done = plugins.smartpromise.defer();
const cycleObject: ICycleObject = {
cycleCounter: cycleCountArg,
deferred: done,
};
this.cycleObjectArray.push(cycleObject);
return done.promise;
}
public informOfCycle(x) {
const newCycleObjectArray: ICycleObject[] = [];
this.cycleObjectArray.forEach((cycleObjectArg) => {
cycleObjectArg.cycleCounter--;
if (cycleObjectArg.cycleCounter <= 0) {
cycleObjectArg.deferred.resolve(x);
} else {
newCycleObjectArray.push(cycleObjectArg);
}
});
this.cycleObjectArray = newCycleObjectArray;
}
}

View File

@ -1,97 +0,0 @@
/// <reference path="./typings/main.d.ts" />
import plugins = require("./taskbuffer.plugins");
import {Task} from "./taskbuffer.classes.task";
export let emptyTaskFunction = function(){
let done = plugins.Q.defer();
done.resolve();
return done.promise;
};
export let isTask = function(taskArg):boolean{
if(
taskArg instanceof Task
&& typeof taskArg.task === "function"
){
return true;
} else {
return false;
}
};
export let isTaskTouched = (taskArg:Task, touchedTasksArray:Task[]):boolean => {
let result = false;
for (let keyArg in touchedTasksArray){
if(taskArg === touchedTasksArray[keyArg]){
result = true;
}
}
return result;
}
export let runTask = function(taskArg:Task,optionsArg:{touchedTasksArray:Task[]} = {touchedTasksArray:[]}){
let done = plugins.Q.defer();
updateTaskStatus(taskArg,"running");
done.promise.then(function(){updateTaskStatus(taskArg,"idle")})
let localDeferred = plugins.Q.defer();
let touchedTasksArray:Task[];
if(optionsArg.touchedTasksArray){
touchedTasksArray = optionsArg.touchedTasksArray;
} else {
touchedTasksArray = [];
}
touchedTasksArray.push(taskArg);
localDeferred.promise
.then(() =>{
if(taskArg.preTask && !isTaskTouched(taskArg.preTask,touchedTasksArray)){
return runTask(taskArg.preTask,{touchedTasksArray:touchedTasksArray})
} else {
let done2 = plugins.Q.defer();
done2.resolve();
return done2.promise;
}
})
.then(() => {
return taskArg.task();
})
.then(() => {
if(taskArg.afterTask && !isTaskTouched(taskArg.afterTask,touchedTasksArray)){
return runTask(taskArg.afterTask,{touchedTasksArray:touchedTasksArray})
} else {
let done2 = plugins.Q.defer();
done2.resolve();
return done2.promise;
}
})
.then(() => {
done.resolve();
});
localDeferred.resolve();
return done.promise;
};
export let runBufferedTask = (taskArg:Task) => {
let recursiveBufferRunner = () => {
if(taskArg.bufferCounter > 0){
taskArg.bufferCounter--;
runTask(taskArg)
.then(recursiveBufferRunner);
}
}
}
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");
}
}

View File

@ -1,72 +1,226 @@
/// <reference path="./typings/main.d.ts" />
import * as plugins from "./taskbuffer.plugins"
import * as helpers from "./taskbuffer.classes.helpers"
import * as plugins from './taskbuffer.plugins';
import { BufferRunner } from './taskbuffer.classes.bufferrunner';
import { CycleCounter } from './taskbuffer.classes.cyclecounter';
import { logger } from './taskbuffer.logging';
export interface ITaskFunction {
(x?: any): PromiseLike<any>;
}
export type TPreOrAfterTaskFunction = () => Task;
export class Task {
name:string;
task:any;
running:boolean;
idle:boolean;
buffered:boolean;
bufferCounter:number;
bufferMax:number;
private _counterTriggerAbsolute:number;
private _state:string;
preTask:Task;
afterTask:Task;
constructor(optionsArg:{
taskFunction:any,
preTask?:Task,
afterTask?:Task,
buffered?:boolean,
bufferMax?:number,
name?:string
}){
if (!optionsArg){optionsArg = {taskFunction:function(){}}}
var options = optionsArg;
this.task = optionsArg.taskFunction;
this.preTask = options.preTask;
this.afterTask = options.afterTask;
this.running = false;
this.idle = true;
this.buffered = options.buffered;
this.bufferMax = options.bufferMax;
this.name = options.name;
// STATIC
public static extractTask(preOrAfterTaskArg: Task | TPreOrAfterTaskFunction): Task {
switch (true) {
case !preOrAfterTaskArg:
return null;
case preOrAfterTaskArg instanceof Task:
return preOrAfterTaskArg as Task;
case typeof preOrAfterTaskArg === 'function':
const taskFunction = preOrAfterTaskArg as TPreOrAfterTaskFunction;
return taskFunction();
default:
return null;
}
trigger(){
let done = plugins.Q.defer();
if(this.buffered) {
this.triggerBuffered()
.then(done.resolve);
}
else {
this.triggerUnBuffered()
.then(done.resolve);
};
return done.promise;
}
public static emptyTaskFunction: ITaskFunction = function (x) {
const done = plugins.smartpromise.defer();
done.resolve();
return done.promise;
};
public static isTask = (taskArg: Task): boolean => {
if (taskArg instanceof Task && typeof taskArg.taskFunction === 'function') {
return true;
} else {
return false;
}
};
public static isTaskTouched = (
taskArg: Task | TPreOrAfterTaskFunction,
touchedTasksArray: Task[]
): boolean => {
const taskToCheck = Task.extractTask(taskArg);
let result = false;
for (const keyArg in touchedTasksArray) {
if (taskToCheck === touchedTasksArray[keyArg]) {
result = true;
}
}
return result;
};
public static runTask = async (
taskArg: Task | TPreOrAfterTaskFunction,
optionsArg: { x?; touchedTasksArray?: Task[] }
) => {
const taskToRun = Task.extractTask(taskArg);
const done = plugins.smartpromise.defer();
// pay respect to execDelay
if (taskToRun.execDelay) {
await plugins.smartdelay.delayFor(taskToRun.execDelay);
}
// set running params
taskToRun.running = true;
done.promise.then(async () => {
taskToRun.running = false;
});
// handle options
const options = {
...{ x: undefined, touchedTasksArray: [] },
...optionsArg,
};
triggerUnBuffered(){
return helpers.runTask(this);
}
triggerBuffered(){
var done = plugins.Q.defer();
if(!(this.bufferCounter >= this.bufferMax)){
this.bufferCounter++
}
helpers.runBufferedTask(this);
return done.promise;
}
const x = options.x;
const touchedTasksArray: Task[] = options.touchedTasksArray;
get state():string {
return this._state;
}
set state(stateArg:string){
if (stateArg == "locked"){
this._state = "locked";
touchedTasksArray.push(taskToRun);
// run the task cascade
const localDeferred = plugins.smartpromise.defer();
localDeferred.promise
.then(() => {
// lets run any preTask
if (taskToRun.preTask && !Task.isTaskTouched(taskToRun.preTask, touchedTasksArray)) {
return Task.runTask(taskToRun.preTask, { x, touchedTasksArray });
} else {
plugins.beautylog.error("state type " + stateArg.blue + " could not be set");
const done2 = plugins.smartpromise.defer();
done2.resolve(x);
return done2.promise;
}
})
.then(async (x) => {
// lets run the main task
try {
return await taskToRun.taskFunction(x);
} catch (e) {
console.log(e);
}
})
.then((x) => {
if (taskToRun.afterTask && !Task.isTaskTouched(taskToRun.afterTask, touchedTasksArray)) {
return Task.runTask(taskToRun.afterTask, { x: x, touchedTasksArray: touchedTasksArray });
} else {
const done2 = plugins.smartpromise.defer();
done2.resolve(x);
return done2.promise;
}
})
.then((x) => {
done.resolve(x);
})
.catch((err) => {
console.log(err);
});
localDeferred.resolve();
return await done.promise;
};
// INSTANCE
// man datory properties
public name: string;
public taskFunction: ITaskFunction;
public buffered: boolean;
public cronJob: plugins.smarttime.CronJob;
public bufferMax: number;
public execDelay: number;
// tasks to run before and after
public preTask: Task | TPreOrAfterTaskFunction;
public afterTask: Task | TPreOrAfterTaskFunction;
// initialize by default
public running: boolean = false;
public bufferRunner = new BufferRunner(this);
public cycleCounter = new CycleCounter(this);
public idle: boolean = true;
private _state: string = 'ready';
constructor(optionsArg: {
/**
* the task function to run, must return promise
*/
taskFunction: ITaskFunction;
/**
* any other task to run before
*/
preTask?: Task | TPreOrAfterTaskFunction;
/**
* any other task to run after
*/
afterTask?: Task | TPreOrAfterTaskFunction;
/**
* wether this task should run buffered
*/
buffered?: boolean;
/**
* the maximum buffer
*/
bufferMax?: number;
/**
* the execution delay, before the task is executed
* only makes sense when running in buffered mode
*/
execDelay?: number;
/**
* the name of the task
*/
name?: string;
}) {
this.taskFunction = optionsArg.taskFunction;
this.preTask = optionsArg.preTask;
this.afterTask = optionsArg.afterTask;
this.idle = !this.running;
this.buffered = optionsArg.buffered;
this.bufferMax = optionsArg.bufferMax;
this.execDelay = optionsArg.execDelay;
this.name = optionsArg.name;
}
/**
* trigger the task. Will trigger buffered if this.buffered is true
*/
public trigger(x?): Promise<any> {
if (this.buffered) {
return this.triggerBuffered(x);
} else {
return this.triggerUnBuffered(x);
}
}
}
/**
* trigger task unbuffered.
*/
public triggerUnBuffered(x?): Promise<any> {
return Task.runTask(this, { x: x });
}
/**
* trigger task buffered.
*/
public triggerBuffered(x?): Promise<any> {
return this.bufferRunner.trigger(x);
}
get state(): string {
return this._state;
}
set state(stateArg: string) {
if (stateArg === 'locked') {
this._state = 'locked';
} else {
logger.log('error', `state type ${stateArg} could not be set`);
}
}
}

View File

@ -1,60 +1,58 @@
/// <reference path="./typings/main.d.ts" />
import * as plugins from "./taskbuffer.plugins";
import {Task} from "./taskbuffer.classes.task";
import helpers = require("./taskbuffer.classes.helpers");
// TaskChain chains tasks
// and extends Task
import * as plugins from './taskbuffer.plugins';
import { Task } from './taskbuffer.classes.task';
import { logger } from './taskbuffer.logging';
export class Taskchain extends Task {
taskArray:Task[];
private _oraObject:plugins.beautylog.Ora;
constructor(optionsArg:{
name?:string,
log?:boolean,
taskArray:Task[]
}){
let options = plugins.lodash.assign(
{
name:"unnamed Taskchain",
log:false
},
optionsArg,
{
taskFunction: () => { // this is the function that gets executed when TaskChain is triggered
let done = plugins.Q.defer(); // this is the starting Deferred object
let taskCounter = 0;
let iterateTasks = () => {
if(typeof this.taskArray[taskCounter] != "undefined"){
this._oraObject.text(this.name + " running: Task" + this.taskArray[taskCounter].name);
this.taskArray[taskCounter].trigger()
.then(()=>{
this._oraObject.log(this.taskArray[taskCounter].name,"ok");
taskCounter++;
iterateTasks();
});
} else {
this._oraObject.endOk("Taskchain \"" + this.name + "\" completed successfully");
done.resolve();
}
};
iterateTasks();
return done.promise;
}
taskArray: Task[];
constructor(optionsArg: {
taskArray: Task[];
name?: string;
log?: boolean;
buffered?: boolean;
bufferMax?: number;
}) {
const options = {
...{
name: 'unnamed Taskchain',
log: false,
},
...optionsArg,
...{
taskFunction: (x: any) => {
// this is the function that gets executed when TaskChain is triggered
const done = plugins.smartpromise.defer(); // this is the starting Deferred object
let taskCounter = 0; // counter for iterating async over the taskArray
const iterateTasks = (x) => {
if (typeof this.taskArray[taskCounter] !== 'undefined') {
console.log(this.name + ' running: Task' + this.taskArray[taskCounter].name);
this.taskArray[taskCounter].trigger(x).then((x) => {
logger.log('info', this.taskArray[taskCounter].name);
taskCounter++;
iterateTasks(x);
});
} else {
console.log('Taskchain "' + this.name + '" completed successfully');
done.resolve(x);
}
);
super(options);
this.taskArray = optionsArg.taskArray;
this._oraObject = new plugins.beautylog.Ora("Taskchain idle","blue");
}
addTask(taskArg:Task){
this.taskArray.push(taskArg);
};
iterateTasks(x);
return done.promise;
},
},
};
removeTask(taskArg:Task){
//TODO
};
shiftTask(){
};
trigger(){
this._oraObject.start(this.name + " running...");
return helpers.runTask(this);
}
};
super(options);
this.taskArray = optionsArg.taskArray;
}
addTask(taskArg: Task) {
this.taskArray.push(taskArg);
}
removeTask(taskArg: Task) {
// TODO:
}
shiftTask() {
// TODO:
}
}

View File

@ -0,0 +1,25 @@
import * as plugins from './taskbuffer.plugins';
import { Task, ITaskFunction } from './taskbuffer.classes.task';
export class TaskDebounced<T = unknown> extends Task {
private _debouncedTaskFunction: ITaskFunction;
private _observableIntake = new plugins.smartrx.ObservableIntake<T>();
constructor(optionsArg: {
name: string;
taskFunction: ITaskFunction;
debounceTimeInMillis: number;
}) {
super({
name: optionsArg.name,
taskFunction: async (x: T) => {
this._observableIntake.push(x);
}
});
this.taskFunction = optionsArg.taskFunction;
this._observableIntake.observable.pipe(plugins.smartrx.rxjs.ops.debounceTime(optionsArg.debounceTimeInMillis)).subscribe((x) => {
this.taskFunction(x);
});
}
}

View File

@ -0,0 +1,107 @@
import * as plugins from './taskbuffer.plugins';
import { Task } from './taskbuffer.classes.task';
import { threadId } from 'worker_threads';
export interface ICronJob {
cronString: string;
taskNameArg: string;
job: any;
}
export class TaskManager {
public taskMap = new plugins.lik.ObjectMap<Task>();
private cronJobManager = new plugins.smarttime.CronManager();
constructor() {
// nothing here
}
/**
* checks if a task is already present
* @param taskNameArg
*/
public getTaskByName(taskNameArg): Task {
return this.taskMap.find((itemArg) => {
return itemArg.name === taskNameArg;
});
}
/**
* adds a Task to the TaskManager
* @param taskArg
*/
public addTask(taskArg: Task): void {
if (!taskArg.name) {
throw new Error('taskArg needs a name to be added to taskManager');
}
this.taskMap.add(taskArg);
}
/**
* adds and schedules a task at once
* @param taskArg
* @param cronStringArg
*/
public addAndScheduleTask(taskArg: Task, cronStringArg: string) {
this.addTask(taskArg);
const taskName = taskArg.name;
this.scheduleTaskByName(taskName, cronStringArg);
}
/**
* triggers a task in the TaskManagerByName
* @param taskNameArg
*/
public triggerTaskByName(taskNameArg: string): Promise<any> {
const taskToTrigger = this.getTaskByName(taskNameArg);
if (!taskToTrigger) {
throw new Error(`There is no task with the name of ${taskNameArg}`);
}
return taskToTrigger.trigger();
}
public async triggerTask(task: Task) {
return task.trigger();
}
/**
* schedules the task by name
* @param taskNameArg
*/
public scheduleTaskByName(taskNameArg: string, cronStringArg: string) {
const taskToSchedule = this.getTaskByName(taskNameArg);
const cronJob = this.cronJobManager.addCronjob(cronStringArg, async () => {
await taskToSchedule.triggerBuffered();
});
taskToSchedule.cronJob = cronJob;
this.cronJobManager.start();
}
/**
* deschedules a task by name
* @param taskNameArg
*/
public descheduleTaskByName(taskNameArg: string) {
const taskToDeSchedule = this.getTaskByName(taskNameArg);
if (taskToDeSchedule.cronJob) {
this.cronJobManager.removeCronjob(taskToDeSchedule.cronJob);
taskToDeSchedule.cronJob = null;
}
if (this.cronJobManager.cronjobs.isEmpty) {
this.cronJobManager.stop();
}
}
/**
* deschedules a task
* @param task
*/
public async descheduleTask(task: Task) {
await this.descheduleTaskByName(task.name);
}
/**
* returns all schedules of a specific task
* @param taskNameArg
*/
public getSchedulesForTaskName(taskNameArg: string) {}
}

View File

@ -0,0 +1,21 @@
import * as plugins from './taskbuffer.plugins';
import { Task, ITaskFunction } from './taskbuffer.classes.task';
/**
* TaskOnce is run exactly once, no matter how often it is triggered
*/
export class TaskOnce extends Task {
hasTriggered: boolean = false;
constructor(optionsArg: { name?: string; taskFunction: ITaskFunction }) {
super({
name: optionsArg.name,
taskFunction: async () => {
if (!this.hasTriggered) {
this.hasTriggered = true;
await optionsArg.taskFunction();
}
},
});
}
}

View File

@ -1,29 +1,24 @@
/// <reference path="./typings/main.d.ts" />
import * as plugins from "./taskbuffer.plugins"
import * as helpers from "./taskbuffer.classes.helpers"
import {Task} from "./taskbuffer.classes.task"
import * as plugins from './taskbuffer.plugins';
import { Task } from './taskbuffer.classes.task';
export class Taskparallel extends Task {
taskArray:Task[];
constructor(optionsArg:{
taskArray:Task[]
}){
let options = plugins.lodash.assign(
optionsArg,
{
taskFunction:() => {
let done = plugins.Q.defer();
let promiseArray; // stores promises of all tasks, since they run in parallel
this.taskArray.forEach(function(taskArg:Task){
promiseArray.push(taskArg.trigger());
})
plugins.Q.all(promiseArray)
.then(done.resolve);
return done.promise;
}
}
)
super(options);
}
public taskArray: Task[];
constructor(optionsArg: { taskArray: Task[] }) {
const options = {
...optionsArg,
...{
taskFunction: () => {
const done = plugins.smartpromise.defer();
const promiseArray: Promise<any>[] = []; // stores promises of all tasks, since they run in parallel
this.taskArray.forEach(function (taskArg) {
promiseArray.push(taskArg.trigger());
});
Promise.all(promiseArray).then(done.resolve);
return done.promise;
},
},
};
super(options);
this.taskArray = optionsArg.taskArray;
}
}

View File

@ -0,0 +1,63 @@
import * as plugins from './taskbuffer.plugins';
import { Task } from './taskbuffer.classes.task';
export class TaskRunner {
public maxParrallelJobs: number = 1;
public status: 'stopped' | 'running' = 'stopped';
public runningTasks: plugins.lik.ObjectMap<Task> = new plugins.lik.ObjectMap<Task>();
public qeuedTasks: Task[] = [];
constructor() {
this.runningTasks.eventSubject.subscribe(async (eventArg) => {
this.checkExecution();
});
}
/**
* adds a task to the qeue
*/
public addTask(taskArg: Task) {
this.qeuedTasks.push(taskArg);
this.checkExecution();
}
/**
* set amount of parallel tasks
* be careful, you might loose dependability of tasks
*/
public setMaxParallelJobs(maxParrallelJobsArg: number) {
this.maxParrallelJobs = maxParrallelJobsArg;
}
/**
* starts the task queue
*/
public async start() {
this.status = 'running';
}
/**
* checks wether execution is on point
*/
public async checkExecution() {
if (
this.runningTasks.getArray().length < this.maxParrallelJobs &&
this.status === 'running' &&
this.qeuedTasks.length > 0
) {
const nextJob = this.qeuedTasks.shift();
this.runningTasks.add(nextJob);
await nextJob.trigger();
this.runningTasks.remove(nextJob);
this.checkExecution();
}
}
/**
* stops the task queue
*/
public async stop() {
this.status = 'stopped';
}
}

View File

@ -1,7 +0,0 @@
/// <reference path="./typings/main.d.ts" />
import * as plugins from "./taskbuffer.plugins"
import * as helpers from "./taskbuffer.classes.helpers"
export class Taskspace {
}

3
ts/taskbuffer.logging.ts Normal file
View File

@ -0,0 +1,3 @@
import * as plugins from './taskbuffer.plugins';
export const logger = new plugins.smartlog.ConsoleLog();

View File

@ -1,4 +1,8 @@
/// <reference path="./typings/main.d.ts" />
export import beautylog = require("beautylog");
export let Q = require("q");
export let lodash= require("lodash");
import * as smartlog from '@pushrocks/smartlog';
import * as lik from '@pushrocks/lik';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartdelay from '@pushrocks/smartdelay';
import * as smartrx from '@pushrocks/smartrx';
import * as smarttime from '@pushrocks/smarttime';
export { smartlog, lik, smartpromise, smartdelay, smartrx, smarttime };

View File

@ -1,8 +0,0 @@
{
"ambientDependencies": {
"colors": "github:DefinitelyTyped/DefinitelyTyped/colors/colors.d.ts",
"mocha": "github:Bartvds/tsd-deftools/typings/DefinitelyTyped/mocha/mocha.d.ts",
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts",
"should": "registry:dt/should#8.1.1+20160316155526"
}
}

17
tslint.json Normal file
View File

@ -0,0 +1,17 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}