Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
3f749dfdd2 | |||
2a39543a75 | |||
68f7d26d3b | |||
6373a74fb3 | |||
be3d2d41d6 | |||
2affa189a7 |
24
.gitignore
vendored
24
.gitignore
vendored
@ -1,4 +1,22 @@
|
|||||||
coverage/
|
|
||||||
node_modules
|
|
||||||
pages/
|
|
||||||
.nogit/
|
.nogit/
|
||||||
|
|
||||||
|
# artifacts
|
||||||
|
coverage/
|
||||||
|
public/
|
||||||
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_web/
|
||||||
|
dist_serve/
|
||||||
|
dist_ts_web/
|
||||||
|
|
||||||
|
# custom
|
@ -1,5 +1,5 @@
|
|||||||
# gitzone ci_default
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
@ -34,48 +34,11 @@ snyk:
|
|||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
sast:
|
|
||||||
stage: security
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
|
|
||||||
variables:
|
|
||||||
DOCKER_DRIVER: overlay2
|
|
||||||
allow_failure: true
|
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command npm run build
|
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
|
||||||
- docker run
|
|
||||||
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
|
|
||||||
--volume "$PWD:/code"
|
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
|
|
||||||
artifacts:
|
|
||||||
reports:
|
|
||||||
sast: gl-sast-report.json
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- priv
|
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
|
|
||||||
testLTS:
|
testStable:
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install lts
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
@ -85,12 +48,24 @@ testSTABLE:
|
|||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
|
testBuild:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci node install lts
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci node install lts
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
@ -103,19 +78,11 @@ release:
|
|||||||
# ====================
|
# ====================
|
||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
script:
|
script:
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
- npmci command npm install -g tslint typescript
|
||||||
- docker run
|
- npmci npm install
|
||||||
--env SOURCE_CODE="$PWD"
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
--volume "$PWD":/code
|
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
|
||||||
artifacts:
|
|
||||||
paths: [codeclimate.json]
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- priv
|
- priv
|
||||||
@ -131,13 +98,15 @@ trigger:
|
|||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: hosttoday/ht-docker-dbase:npmci
|
||||||
|
services:
|
||||||
|
- docker:stable-dind
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g typedoc typescript
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
@ -3,5 +3,15 @@
|
|||||||
"npmGlobalTools": [],
|
"npmGlobalTools": [],
|
||||||
"npmAccessLevel": "public",
|
"npmAccessLevel": "public",
|
||||||
"npmRegistryUrl": "registry.npmjs.org"
|
"npmRegistryUrl": "registry.npmjs.org"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "pushrocks",
|
||||||
|
"gitrepo": "taskbuffer",
|
||||||
|
"shortDescription": "flexible task management. TypeScript ready!",
|
||||||
|
"npmPackagename": "@pushrocks/taskbuffer",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
36
package-lock.json
generated
36
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/taskbuffer",
|
"name": "@pushrocks/taskbuffer",
|
||||||
"version": "2.0.8",
|
"version": "2.0.11",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -229,9 +229,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@pushrocks/smartpromise": {
|
"@pushrocks/smartpromise": {
|
||||||
"version": "3.0.2",
|
"version": "3.0.5",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-3.0.2.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-3.0.5.tgz",
|
||||||
"integrity": "sha512-jmrJMUEmBCWChWK8CIcx4Vw3wv/8OgVNmkaxJrbs+WMaoRUfJtpWWJfrAwwHWt9ZXJbarJ+CwfwfYiiZXymndQ=="
|
"integrity": "sha512-9kHBWyDFjQ6cV1rseOfge02EH6huh/mrtqxlFoJoxnMaGWf5F8H3UEsskBBUGI6QKE1Bl8evr74AIKWwJ0r/bA=="
|
||||||
},
|
},
|
||||||
"@pushrocks/smartrequest": {
|
"@pushrocks/smartrequest": {
|
||||||
"version": "1.1.23",
|
"version": "1.1.23",
|
||||||
@ -387,9 +387,9 @@
|
|||||||
"integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA=="
|
"integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA=="
|
||||||
},
|
},
|
||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "12.7.4",
|
"version": "12.7.5",
|
||||||
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.7.4.tgz",
|
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.7.5.tgz",
|
||||||
"integrity": "sha512-W0+n1Y+gK/8G2P/piTkBBN38Qc5Q1ZSO6B5H3QmPCUewaiXOo2GCAWZ4ElZCcNhjJuBSUSLGFUJnmlCn5+nxOQ=="
|
"integrity": "sha512-9fq4jZVhPNW8r+UYKnxF1e2HkDWOWKM5bC2/7c9wPV835I0aOrVbS/Hw/pWPk2uKrNXQqg9Z959Kz+IYDd5p3w=="
|
||||||
},
|
},
|
||||||
"@types/vinyl": {
|
"@types/vinyl": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
@ -641,9 +641,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"cron": {
|
"cron": {
|
||||||
"version": "1.7.1",
|
"version": "1.7.2",
|
||||||
"resolved": "https://verdaccio.lossless.one/cron/-/cron-1.7.1.tgz",
|
"resolved": "https://verdaccio.lossless.one/cron/-/cron-1.7.2.tgz",
|
||||||
"integrity": "sha512-gmMB/pJcqUVs/NklR1sCGlNYM7TizEw+1gebz20BMc/8bTm/r7QUp3ZPSPlG8Z5XRlvb7qhjEjq/+bdIfUCL2A==",
|
"integrity": "sha512-+SaJ2OfeRvfQqwXQ2kgr0Y5pzBR/lijf5OpnnaruwWnmI799JfWr2jN2ItOV9s3A/+TFOt6mxvKzQq5F0Jp6VQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"moment-timezone": "^0.5.x"
|
"moment-timezone": "^0.5.x"
|
||||||
}
|
}
|
||||||
@ -1467,16 +1467,16 @@
|
|||||||
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ=="
|
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ=="
|
||||||
},
|
},
|
||||||
"tslint": {
|
"tslint": {
|
||||||
"version": "5.19.0",
|
"version": "5.20.0",
|
||||||
"resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.19.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.20.0.tgz",
|
||||||
"integrity": "sha512-1LwwtBxfRJZnUvoS9c0uj8XQtAnyhWr9KlNvDIdB+oXyT+VpsOAaEhEgKi1HrZ8rq0ki/AAnbGSv4KM6/AfVZw==",
|
"integrity": "sha512-2vqIvkMHbnx8acMogAERQ/IuINOq6DFqgF8/VDvhEkBqQh/x6SP0Y+OHnKth9/ZcHQSroOZwUQSN18v8KKF0/g==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"@babel/code-frame": "^7.0.0",
|
"@babel/code-frame": "^7.0.0",
|
||||||
"builtin-modules": "^1.1.1",
|
"builtin-modules": "^1.1.1",
|
||||||
"chalk": "^2.3.0",
|
"chalk": "^2.3.0",
|
||||||
"commander": "^2.12.1",
|
"commander": "^2.12.1",
|
||||||
"diff": "^3.2.0",
|
"diff": "^4.0.1",
|
||||||
"glob": "^7.1.1",
|
"glob": "^7.1.1",
|
||||||
"js-yaml": "^3.13.1",
|
"js-yaml": "^3.13.1",
|
||||||
"minimatch": "^3.0.4",
|
"minimatch": "^3.0.4",
|
||||||
@ -1485,14 +1485,6 @@
|
|||||||
"semver": "^5.3.0",
|
"semver": "^5.3.0",
|
||||||
"tslib": "^1.8.0",
|
"tslib": "^1.8.0",
|
||||||
"tsutils": "^2.29.0"
|
"tsutils": "^2.29.0"
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"diff": {
|
|
||||||
"version": "3.5.0",
|
|
||||||
"resolved": "https://verdaccio.lossless.one/diff/-/diff-3.5.0.tgz",
|
|
||||||
"integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==",
|
|
||||||
"dev": true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tslint-config-prettier": {
|
"tslint-config-prettier": {
|
||||||
|
23
package.json
23
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/taskbuffer",
|
"name": "@pushrocks/taskbuffer",
|
||||||
"version": "2.0.8",
|
"version": "2.0.11",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "flexible task management. TypeScript ready!",
|
"description": "flexible task management. TypeScript ready!",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@ -30,17 +30,28 @@
|
|||||||
"@pushrocks/lik": "^3.0.11",
|
"@pushrocks/lik": "^3.0.11",
|
||||||
"@pushrocks/smartdelay": "^2.0.3",
|
"@pushrocks/smartdelay": "^2.0.3",
|
||||||
"@pushrocks/smartlog": "^2.0.19",
|
"@pushrocks/smartlog": "^2.0.19",
|
||||||
"@pushrocks/smartpromise": "^3.0.2",
|
"@pushrocks/smartpromise": "^3.0.5",
|
||||||
"@types/cron": "^1.7.1",
|
"@types/cron": "^1.7.1",
|
||||||
"cron": "^1.7.1",
|
"cron": "^1.7.2",
|
||||||
"rxjs": "^6.5.3"
|
"rxjs": "^6.5.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.17",
|
"@gitzone/tsbuild": "^2.1.17",
|
||||||
"@gitzone/tstest": "^1.0.24",
|
"@gitzone/tstest": "^1.0.24",
|
||||||
"@pushrocks/tapbundle": "^3.0.13",
|
"@pushrocks/tapbundle": "^3.0.13",
|
||||||
"@types/node": "^12.7.4",
|
"@types/node": "^12.7.5",
|
||||||
"tslint": "^5.19.0",
|
"tslint": "^5.20.0",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
}
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/*",
|
||||||
|
"ts_web/*",
|
||||||
|
"dist/*",
|
||||||
|
"dist_web/*",
|
||||||
|
"dist_ts_web/*",
|
||||||
|
"assets/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
77
readme.md
77
readme.md
@ -1,64 +1,22 @@
|
|||||||
# taskbuffer
|
# @pushrocks/taskbuffer
|
||||||
|
|
||||||
flexible task management. TypeScript ready!
|
flexible task management. TypeScript ready!
|
||||||
|
|
||||||
## Availabililty
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/taskbuffer)
|
||||||
[](https://www.npmjs.com/package/taskbuffer)
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/taskbuffer)
|
||||||
[](https://GitLab.com/pushrocks/taskbuffer)
|
* [github.com (source mirror)](https://github.com/pushrocks/taskbuffer)
|
||||||
[](https://github.com/pushrocks/taskbuffer)
|
* [docs (typedoc)](https://pushrocks.gitlab.io/taskbuffer/)
|
||||||
[](https://pushrocks.gitlab.io/taskbuffer/)
|
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
|
[](https://gitlab.com/pushrocks/taskbuffer/commits/master)
|
||||||
|
[](https://gitlab.com/pushrocks/taskbuffer/commits/master)
|
||||||
|
[](https://www.npmjs.com/package/@pushrocks/taskbuffer)
|
||||||
|
[](https://snyk.io/test/npm/@pushrocks/taskbuffer)
|
||||||
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
[](https://prettier.io/)
|
||||||
|
|
||||||
[](https://GitLab.com/pushrocks/taskbuffer/commits/master)
|
## Usage
|
||||||
[](https://GitLab.com/pushrocks/taskbuffer/commits/master)
|
|
||||||
[](https://www.npmjs.com/package/taskbuffer)
|
|
||||||
[](https://david-dm.org/pushrocks/taskbuffer)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/taskbuffer/master/dependencies/npm)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/taskbuffer)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](http://standardjs.com/)
|
|
||||||
|
|
||||||
## 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**.
|
We highly recommend TypeScript as this module supports **TypeScript intellisense**.
|
||||||
|
|
||||||
@ -85,3 +43,10 @@ For further information read the linked docs at the top of this README.
|
|||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
|
||||||
[](https://push.rocks)
|
[](https://push.rocks)
|
||||||
|
|
||||||
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
|
[](https://maintainedby.lossless.com)
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
import plugins = require('./taskbuffer.plugins');
|
import plugins = require('./taskbuffer.plugins');
|
||||||
import { Task, ITaskFunction } from './taskbuffer.classes.task';
|
import { Task, ITaskFunction } from './taskbuffer.classes.task';
|
||||||
|
|
||||||
export let emptyTaskFunction: ITaskFunction = function(x) {
|
export const emptyTaskFunction: ITaskFunction = function(x) {
|
||||||
let done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
done.resolve();
|
done.resolve();
|
||||||
return done.promise;
|
return done.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
export let isTask = function(taskArg: Task): boolean {
|
export const isTask = (taskArg: Task): boolean => {
|
||||||
if (taskArg instanceof Task && typeof taskArg.taskFunction === 'function') {
|
if (taskArg instanceof Task && typeof taskArg.taskFunction === 'function') {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@ -15,9 +15,9 @@ export let isTask = function(taskArg: Task): boolean {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export let isTaskTouched = (taskArg: Task, touchedTasksArray: Task[]): boolean => {
|
export const isTaskTouched = (taskArg: Task, touchedTasksArray: Task[]): boolean => {
|
||||||
let result = false;
|
let result = false;
|
||||||
for (let keyArg in touchedTasksArray) {
|
for (const keyArg in touchedTasksArray) {
|
||||||
if (taskArg === touchedTasksArray[keyArg]) {
|
if (taskArg === touchedTasksArray[keyArg]) {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
@ -25,8 +25,8 @@ export let isTaskTouched = (taskArg: Task, touchedTasksArray: Task[]): boolean =
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
export let runTask = async (taskArg: Task, optionsArg: { x?; touchedTasksArray?: Task[] }) => {
|
export const runTask = async (taskArg: Task, optionsArg: { x?; touchedTasksArray?: Task[] }) => {
|
||||||
let done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
|
|
||||||
// pay respect to execDelay
|
// pay respect to execDelay
|
||||||
if (taskArg.execDelay) {
|
if (taskArg.execDelay) {
|
||||||
@ -41,35 +41,41 @@ export let runTask = async (taskArg: Task, optionsArg: { x?; touchedTasksArray?:
|
|||||||
});
|
});
|
||||||
|
|
||||||
// handle options
|
// handle options
|
||||||
let options = {
|
const options = {
|
||||||
...{ x: undefined, touchedTasksArray: [] },
|
...{ x: undefined, touchedTasksArray: [] },
|
||||||
...optionsArg
|
...optionsArg
|
||||||
};
|
};
|
||||||
let x = options.x;
|
const x = options.x;
|
||||||
let touchedTasksArray: Task[] = options.touchedTasksArray;
|
const touchedTasksArray: Task[] = options.touchedTasksArray;
|
||||||
|
|
||||||
touchedTasksArray.push(taskArg);
|
touchedTasksArray.push(taskArg);
|
||||||
|
|
||||||
// run the task cascade
|
// run the task cascade
|
||||||
let localDeferred = plugins.smartpromise.defer();
|
const localDeferred = plugins.smartpromise.defer();
|
||||||
localDeferred.promise
|
localDeferred.promise
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
// lets run any preTask
|
||||||
if (taskArg.preTask && !isTaskTouched(taskArg.preTask, touchedTasksArray)) {
|
if (taskArg.preTask && !isTaskTouched(taskArg.preTask, touchedTasksArray)) {
|
||||||
return runTask(taskArg.preTask, { x: x, touchedTasksArray: touchedTasksArray });
|
return runTask(taskArg.preTask, { x, touchedTasksArray });
|
||||||
} else {
|
} else {
|
||||||
let done2 = plugins.smartpromise.defer();
|
const done2 = plugins.smartpromise.defer();
|
||||||
done2.resolve(x);
|
done2.resolve(x);
|
||||||
return done2.promise;
|
return done2.promise;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(x => {
|
.then(async x => {
|
||||||
return taskArg.taskFunction(x);
|
// lets run the main task
|
||||||
|
try {
|
||||||
|
return await taskArg.taskFunction(x);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(x => {
|
.then(x => {
|
||||||
if (taskArg.afterTask && !isTaskTouched(taskArg.afterTask, touchedTasksArray)) {
|
if (taskArg.afterTask && !isTaskTouched(taskArg.afterTask, touchedTasksArray)) {
|
||||||
return runTask(taskArg.afterTask, { x: x, touchedTasksArray: touchedTasksArray });
|
return runTask(taskArg.afterTask, { x: x, touchedTasksArray: touchedTasksArray });
|
||||||
} else {
|
} else {
|
||||||
let done2 = plugins.smartpromise.defer();
|
const done2 = plugins.smartpromise.defer();
|
||||||
done2.resolve(x);
|
done2.resolve(x);
|
||||||
return done2.promise;
|
return done2.promise;
|
||||||
}
|
}
|
||||||
@ -96,8 +102,8 @@ export class CycleCounter {
|
|||||||
this.task = taskArg;
|
this.task = taskArg;
|
||||||
}
|
}
|
||||||
getPromiseForCycle(cycleCountArg: number) {
|
getPromiseForCycle(cycleCountArg: number) {
|
||||||
let done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
let cycleObject: cycleObject = {
|
const cycleObject: cycleObject = {
|
||||||
cycleCounter: cycleCountArg,
|
cycleCounter: cycleCountArg,
|
||||||
deferred: done
|
deferred: done
|
||||||
};
|
};
|
||||||
@ -105,7 +111,7 @@ export class CycleCounter {
|
|||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
informOfCycle(x) {
|
informOfCycle(x) {
|
||||||
let newCycleObjectArray: cycleObject[] = [];
|
const newCycleObjectArray: cycleObject[] = [];
|
||||||
this.cycleObjectArray.forEach(cycleObjectArg => {
|
this.cycleObjectArray.forEach(cycleObjectArg => {
|
||||||
cycleObjectArg.cycleCounter--;
|
cycleObjectArg.cycleCounter--;
|
||||||
if (cycleObjectArg.cycleCounter <= 0) {
|
if (cycleObjectArg.cycleCounter <= 0) {
|
||||||
@ -131,7 +137,7 @@ export class BufferRunner {
|
|||||||
if (!(this.bufferCounter >= this.task.bufferMax)) {
|
if (!(this.bufferCounter >= this.task.bufferMax)) {
|
||||||
this.bufferCounter++;
|
this.bufferCounter++;
|
||||||
}
|
}
|
||||||
let returnPromise: Promise<any> = this.task.cycleCounter.getPromiseForCycle(
|
const returnPromise: Promise<any> = this.task.cycleCounter.getPromiseForCycle(
|
||||||
this.bufferCounter + 1
|
this.bufferCounter + 1
|
||||||
);
|
);
|
||||||
if (!this.running) {
|
if (!this.running) {
|
||||||
@ -141,7 +147,7 @@ export class BufferRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _run(x) {
|
private _run(x) {
|
||||||
let recursiveBufferRunner = x => {
|
const recursiveBufferRunner = x => {
|
||||||
if (this.bufferCounter >= 0) {
|
if (this.bufferCounter >= 0) {
|
||||||
this.running = true;
|
this.running = true;
|
||||||
this.task.running = true;
|
this.task.running = true;
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
import * as plugins from './taskbuffer.plugins';
|
import * as plugins from './taskbuffer.plugins';
|
||||||
import { Task } from './taskbuffer.classes.task';
|
import { Task } from './taskbuffer.classes.task';
|
||||||
|
|
||||||
// interfaces
|
export interface ICronJob {
|
||||||
import { Objectmap } from '@pushrocks/lik';
|
cronString: string;
|
||||||
|
taskNameArg: string;
|
||||||
|
job: any;
|
||||||
|
}
|
||||||
|
|
||||||
export class TaskManager {
|
export class TaskManager {
|
||||||
public taskMap = new plugins.lik.Objectmap<Task>();
|
public taskMap = new plugins.lik.Objectmap<Task>();
|
||||||
private cronJobMap = new plugins.lik.Objectmap<ICronJob>();
|
private cronJobMap = new plugins.lik.Objectmap<ICronJob>();
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
// nothing here
|
// nothing here
|
||||||
}
|
}
|
||||||
@ -55,6 +59,10 @@ export class TaskManager {
|
|||||||
return taskToTrigger.trigger();
|
return taskToTrigger.trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async triggerTask(task: Task) {
|
||||||
|
return task.trigger();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* schedules the task by name
|
* schedules the task by name
|
||||||
* @param taskNameArg
|
* @param taskNameArg
|
||||||
@ -71,25 +79,31 @@ export class TaskManager {
|
|||||||
this.cronJobMap.add({
|
this.cronJobMap.add({
|
||||||
taskNameArg: taskToSchedule.name,
|
taskNameArg: taskToSchedule.name,
|
||||||
cronString: cronStringArg,
|
cronString: cronStringArg,
|
||||||
job: job
|
job
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deschedules a task by name
|
||||||
|
* @param taskNameArg
|
||||||
|
*/
|
||||||
public descheduleTaskByName(taskNameArg: string) {
|
public descheduleTaskByName(taskNameArg: string) {
|
||||||
const descheduledCron = this.cronJobMap.findOneAndRemove(itemArg => {
|
const descheduledCron = this.cronJobMap.findOneAndRemove(itemArg => {
|
||||||
return itemArg.taskNameArg === taskNameArg;
|
return itemArg.taskNameArg === taskNameArg;
|
||||||
});
|
});
|
||||||
descheduledCron.job.stop();
|
descheduledCron.job.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deschedules a task
|
||||||
|
* @param task
|
||||||
|
*/
|
||||||
|
public async descheduleTask(task: Task) {
|
||||||
|
await this.descheduleTaskByName(task.name);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* returns all schedules of a specific task
|
* returns all schedules of a specific task
|
||||||
* @param taskNameArg
|
* @param taskNameArg
|
||||||
*/
|
*/
|
||||||
public getSchedulesForTaskName(taskNameArg: string) {}
|
public getSchedulesForTaskName(taskNameArg: string) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ICronJob {
|
|
||||||
cronString: string;
|
|
||||||
taskNameArg: string;
|
|
||||||
job: any;
|
|
||||||
}
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import * as smartlog from '@pushrocks/smartlog';
|
import * as smartlog from '@pushrocks/smartlog';
|
||||||
let cron = require('cron');
|
import cron from 'cron';
|
||||||
import * as lik from '@pushrocks/lik';
|
import * as lik from '@pushrocks/lik';
|
||||||
import * as rxjs from 'rxjs';
|
import * as rxjs from 'rxjs';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
Reference in New Issue
Block a user